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# - 如何删除 WPF 中的系统菜单?

c - 为什么忽略字符串循环?

python - 输出在字符串中找到的特定单词(从列表中)

c# - 如何通过换行字典<string,string>将字符串拆分为键值对

c# - 使用不带参数的 catch

c# - groupbox.Controls[i] 或 panel.Controls[i] 如何工作?

java获取字符串中的下几个单词

python - 如何拆分列表并将其打印在不同的行中?

c# - Window.open 将父页面导航到代码行 url

c# - 在azure函数中配置 token