Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从字符串中的某个字符中获取以前的字符。例如:myString = "26+",所以我想得到不带 + 的 26。我怎样才能做到这一点?
使用Substring和IndexOf。
string str = "26+"; string requiredString = str.Substring(0, str.IndexOf('+'));
strings在 C# 中是不可变的,您必须将结果分配给字符串itself或某个other字符串。
strings
itself
other
函数 String.Substring 将满足您的需求。
yourString.Substring(0, keepCharactersBeforeHere);