通过在字符串中指定char来查找字符位置长 [英] Find character position lengh by specify char in string

查看:131
本文介绍了通过在字符串中指定char来查找字符位置长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的字符串''C21F-6573-34E0-C3F0-PNBM-QUR7-4VXT-TAXC-U0/H-XW ==''
0123456789012345678901234567890123456789012345678
< ---- 1 --->< ---- 2 --->< ---- 3 --->< ---- 4 --->< ---- 5->
上一个字符串的总字符数为49.
我想从左侧的``P''字符到结束点拾取子字符串,即起始索引位置为19.
但是我想在上面的字符串中搜索``-''(破折号).

我该如何解决以上问题??
请帮助我.....

This my String ''C21F-6573-34E0-C3F0-PNBM-QUR7-4VXT-TAXC-U0/H-XW==''
0123456789012345678901234567890123456789012345678
<----1---><----2---><----3---><----4---><----5-->
Total no character is 49 of above string.
I want to pick up the substring from left side ''P'' char to end point, i.e. starting index position is 19.
But i want to searching ''-''(dash sign) in the above string.

How will i solve above problem???
Please help me.....

推荐答案


如果您的字符串是固定格式,则
If your string is fixed format, then String.Substring[^] is the easy way:
Dim part As String = full.Substring(20)


如果您确实需要根据第四个连字符后的数据处理可变位置,请使用Regex:


If you really need to work with a variable position, based on the data after the fourth hyphen, then use a Regex:

'  Imports System.Text.RegularExpressions

'  Regular expression built for Visual Basic on: Wed, Dec 21, 2011, 07:58:27 AM
'  Using Expresso Version: 3.0.3634, http://www.ultrapico.com
'  
'  A description of the regular expression:
'  
'  Match a prefix but exclude it from the capture. [\w+-\w+-\w+-\w+-]
'      \w+-\w+-\w+-\w+-
'          Alphanumeric, one or more repetitions
'          -
'          Alphanumeric, one or more repetitions
'          -
'          Alphanumeric, one or more repetitions
'          -
'          Alphanumeric, one or more repetitions
'          -
'  [1]: A numbered capture group. [.*]
'      Any character, any number of repetitions
'  
'

Public Dim regex As Regex = New Regex( _
      "(?<=\w+-\w+-\w+-\w+-)(.*)", _
    RegexOptions.IgnoreCase _
    Or RegexOptions.Multiline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
    )


' This is the replacement string
Public Dim regexReplace As String = _
      "


&


这篇关于通过在字符串中指定char来查找字符位置长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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