c# - 如何将字符串拆分为数组?

标签 c# split

我想将一个字符串拆分成一个数组。字符串如下:

:hello:mr.zoghal:

我想将其拆分如下:

hello mr.zoghal

我试过了...

string[] split = string.Split(new Char[] {':'});

现在我想要:

  string  something = hello ;
  string  something1 = mr.zoghal;

我怎样才能做到这一点?

最佳答案

String myString = ":hello:mr.zoghal:";

string[] split = myString.Split(':');

string newString = string.Empty;

foreach(String s in split) {
 newString += "something = " + s + "; ";
}

您的输出将是: 某事=你好;某事= Zoghal 先生;

关于c# - 如何将字符串拆分为数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1203966/

相关文章:

c# - 我如何计算列表中的重复项并更改项目值

c# - 无法使用异步/等待连接到异步服务器

vbscript - 拆分字符串值并将它们分配给 VBscript 中的变量

bash - 按行拆分文件并将第一个字符串保留为输出文件的标题

c# - 在 C# 中处理窗体上的控件时何时使用 THIS 关键字

c# - 自定义 JsonConverter 不调用 ReadJson

python - 尝试在 python 中的 stdin 上使用 split()

python - 根据 pandas 数据框中的条件将单元格拆分/分解为多行

java - 类似于 split() 的东西?

c# - 如何在 C# 中使用 HttpClient GetAsync 方法传递请求内容