C# 程序拆分字符串时使用空格
首先,设置一个字符串 -
string str = "Science and Mathematics";
现在使用 Split() 方法在所有空格出现的地方进行拆分 -
str.Split(' ')以下为完整代码 -
示例
using System;
using System.Linq;
using System.IO;
class Program {
static void Main() {
string str = "Science and Mathematics";
Console.WriteLine("String...
"+str);
string[] myStr = str.Split(' ');
Console.WriteLine("
Splitted String...");
foreach (string ch in myStr) {
Console.WriteLine(ch);
}
}
}输出
String... Science and Mathematics Splitted String... Science and Mathematics
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP