C# 如何分割字符串? $$
如何从该字符串中获取C# 如何分割字符串? $$,c#,C#,如何从该字符串中获取和。美元左右的一切 不需要是正则表达式。好吧,您可以使用: <span style="cursor: pointer;">$$</span> 请注意,与使用char分隔符的重载不同,您必须提供StringSplitOptions,并且必须手动创建数组。(当然,如果要重复执行此操作,可能需要重用该数组。)还可以选择指定要将输入拆分为的最大令牌数。有关更多信息,请参阅 简短但完整的程序: string[] bits = input.Split(new s
和
。美元左右的一切
不需要是正则表达式。好吧,您可以使用:
<span style="cursor: pointer;">$$</span>
请注意,与使用char
分隔符的重载不同,您必须提供StringSplitOptions
,并且必须手动创建数组。(当然,如果要重复执行此操作,可能需要重用该数组。)还可以选择指定要将输入拆分为的最大令牌数。有关更多信息,请参阅
简短但完整的程序:
string[] bits = input.Split(new string[]{"$$"}, StringSplitOptions.None);
好吧,你可以用:
<span style="cursor: pointer;">$$</span>
请注意,与使用char
分隔符的重载不同,您必须提供StringSplitOptions
,并且必须手动创建数组。(当然,如果要重复执行此操作,可能需要重用该数组。)还可以选择指定要将输入拆分为的最大令牌数。有关更多信息,请参阅
简短但完整的程序:
string[] bits = input.Split(new string[]{"$$"}, StringSplitOptions.None);
或者可以使用IndexOf查找“$$”,然后使用Substring方法获取任意一方 范例
int separatorIndex = input.IndexOf("$$");
if (separatorIndex == -1)
{
throw new ArgumentException("input", "Oh noes, couldn't find $$");
}
string firstBit = input.Substring(0, separatorIndex);
string secondBit = input.Substring(separatorIndex + 2);
string s=“$$”;
字符串findValue=“$$”;
int index=s.IndexOf(findValue);
字符串left=s.Substring(0,索引);
string right=s.Substring(索引+findValue.Length);
或者您可以使用IndexOf查找“$$”,然后使用子字符串方法获取任意一方
范例
int separatorIndex = input.IndexOf("$$");
if (separatorIndex == -1)
{
throw new ArgumentException("input", "Oh noes, couldn't find $$");
}
string firstBit = input.Substring(0, separatorIndex);
string secondBit = input.Substring(separatorIndex + 2);
string s=“$$”;
字符串findValue=“$$”;
int index=s.IndexOf(findValue);
字符串left=s.Substring(0,索引);
string right=s.Substring(索引+findValue.Length);
您可以使用SubString()方法:
string_str=“$$”;
int index=_str.IndexOf($);
字符串_a=_str.Substring(0,索引);
字符串_b=_str.Substring(索引+2,(_str.Length-index-2));
Mitja您可以使用SubString()方法:
string_str=“$$”;
int index=_str.IndexOf($);
字符串_a=_str.Substring(0,索引);
字符串_b=_str.Substring(索引+2,(_str.Length-index-2));
Mitja我只是在我的答案中加入了这一点:):)我对Skeet传说的期望不会降低。我只是在我的答案中加入了这一点:):)我对Skeet传说的期望不会降低