如何提取子字符串 [英] How to extract the sub string

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

问题描述

我想提取两个字符之间的子字符串

I want to extrct the substring between two char

推荐答案

如果您事先知道两个字符的位置,则可以使用(足够奇怪) String.Substring [ String.IndexOf [ ^ ]方法).
或者,您可以使用正则表达式类 [
If you know in advance the positions of the two chars then you may use (strangely enough) the String.Substring[^].
On the other hand, if you don''t know such positions then you need to first locate them (via, for instance the String.IndexOf[^] method).
Alternatively, you may use the Regex Class[^].


有几种方法可以实现.

您可以使用正则表达式提取该子字符串,也可以只使用Substring方法.

检查此链接以了解正则表达式的方式:
30分钟正则表达式教程 [ http://msdn.microsoft.com/en-us/library/aka44szs.aspx [ ^ ].


下次在您的问题上更具体一些,以便我们为您提供更清洁的解决方案.


干杯
There are several approaches to achieve that.

You can use an regular expression to extract that substring, or you can simply use Substring method.

Check this link for the Regex way:
The 30 Minute Regex Tutorial[^]

or this on how to use the substring method
http://msdn.microsoft.com/en-us/library/aka44szs.aspx[^].


Next time be more concrete on your question so we can suggest you a cleaner solution.


Cheers


这篇关于如何提取子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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