[英]How can I split a string with " as delimiter?
try
{
settings =System.IO.File.ReadAllLines("config.txt");
foreach(string setting in settings)
{
Console.WriteLine( setting.Split('"' ));
}
}
How can I split the string with my delimiter of "
. I just want to get that half so I can write my config file. I am a C++ programmer but my current project requires c#. my return value that I keep on getting is System.string[]
. Thank you! 如何用"
。 "
分隔符拆分字符串。我只想得到那一半所以我可以编写我的配置文件。我是一名C ++程序员,但我当前的项目需要c#。我继续得到的返回值是System.string[]
。谢谢!
settings.Split('\"');
You have to escape the quote. 你必须逃避报价。
Actually, you don't even have to do that when using '
. 实际上,使用'
时甚至不需要这样做。
void Main()
{
string test = "\"test1\"test2";
var arr = test.Split('"');
Console.WriteLine (arr);
}
Will output 会输出
test1
test2
public string[] Split(
params char[] separator
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.