如何根据字符删除字符串 [英] How to remove string based on chars

查看:80
本文介绍了如何根据字符删除字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想修剪字符直到??值

我的字符串就像字符串值=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) with System.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 of System.String members, for example, Length, IndexOf(String) and Substring(Int32), another way would be using Split(Char[], StringSplitOptions) or Split(String[], StringSplitOptions) with System.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆