Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# split用法

作者:碎花洋裙的优雅   发布日期:2025-11-06   浏览:137

// 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

大家都在看

c# 二进制

c# datatable group by

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#获取系统时间

c#游戏开发

c#网络编程

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站