// C# Split 用法示例
using System;
class Program
{
static void Main()
{
// 定义一个字符串
string text = "Hello,World,This,Is,CSharp";
// 使用逗号作为分隔符进行分割
string[] words = text.Split(',');
// 输出分割后的结果
foreach (string word in words)
{
Console.WriteLine(word);
}
}
}
text.Split(','):使用逗号 , 作为分隔符,将字符串 text 分割成多个子字符串,并返回一个字符串数组。foreach (string word in words):遍历分割后的字符串数组 words,并逐个输出每个子字符串。如果需要更复杂的分割规则(例如忽略空白字符或使用多个分隔符),可以传递更多的参数给 Split 方法。
上一篇:c#高并发
下一篇:c# if else
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站