如何在'\'
之后阅读字符:
string PrName = "software\Plan Mobile";
答案 0 :(得分:2)
首先,不要忘记@
:
string PrName = @"software\Plan Mobile";
接下来,如果您只想要尾部(即"Plan Mobile"
),那么Substring
将会:
// if no '\' found, the entire string will be return
string tail = PrName.Substring(PrName.IndexOf('\\') + 1);
如果您想要两者(所有部分),请尝试Split
:
// parts[0] == "software"
// parts[1] == "Plan Mobile"
string[] parts = PrName.Split('\\');
答案 1 :(得分:0)
试试这个:
char charToFind = '\';
string PrName = "software\Plan Mobile";
int indexOfChar = PrName.IndexOf(charToFind);
if (indexOfChar >= 0)
{
string result = PrName.Substring(indexOfChar + 1);
}
输出:result = "Plan Mobile"
答案 2 :(得分:0)
我想,你想拆分字符串
string s = "software\Plan Mobile";
// Split string on '\'.
string[] words = s.Split('\');
foreach (string word in words)
{
Console.WriteLine(word);
}
<强>输出:强>
software
Plan mobile