如何根据字符删除字符串 [英] How to remove string based on chars
本文介绍了如何根据字符删除字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想修剪字符直到??值
我的字符串就像字符串值=suhel ?? 78a;
我想要字符串value2 =suhel ??;我想修剪价值的东西?标记符号可以引导或发送片段。
Hi All,
I want to trim chars till ?? values
I have string like string values="suhel??78a";
I want string value2="suhel??"; I want to Trim values what ever afer ?? marks symbol can you guide or send snippets.
推荐答案
例如,您可以使用正则表达式:
http://en.wikipedia.org/wiki/Regular_Expression [ ^ ],
https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex%28v=vs.110%29。 aspx [ ^ ]。
你可以通过System.String的某种组合来做同样的事情
成员,例如,长度
,IndexOf(String)
和子串(Int32)
,另一种方法是使用Split(Char [],StringSplitOptions)
或Split(String [],StringSplitOptions)
withSystem.StringSplitOptions.RemoveEmptyEntries
:
https://msdn.microsoft .com / zh-cn / library / system.string%28v = vs.110%29.aspx [ ^ ]。
-SA
You can use, for example, regular expressions:
http://en.wikipedia.org/wiki/Regular_Expression[^],
https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex%28v=vs.110%29.aspx[^].
You can do the same by some combination ofSystem.String
members, for example,Length
,IndexOf(String)
andSubstring(Int32)
, another way would be usingSplit(Char[], StringSplitOptions)
orSplit(String[], StringSplitOptions)
withSystem.StringSplitOptions.RemoveEmptyEntries
:
https://msdn.microsoft.com/en-us/library/system.string%28v=vs.110%29.aspx[^].
—SA
首先,使用 IndexOf [ ^ ]找到??的位置在字符串中,然后使用子字符串 [ ^ ]提取您想要的部分。
First, use IndexOf[^] to locate the position of the ?? in the string, then use Substring[^] to extract the part that you want.
这篇关于如何根据字符删除字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文