在字符和sysmbol之间进行解析 [英] Parsing between a character and sysmbol
问题描述
我有一个如下字符串:
10AF101-25
我想提取之前之前的任何数字; - "并且
在遇到像AF这样的字符串字符时停止
所以我的结果应该是101.
任何帮助表示赞赏。
Dim x As String =" 10AF101-25"
Dim y As String( )= x.split(" - ")
Dim z As String
dim i As Integer
For i = 0到y(0)。长度
如果IsNumeric(y(i))那么z = y& = y(i)
下一页
< ge ********* @ gmail.comwrote in message
news:11 ************** ********@75g2000cwc.googlegro ups.com ...
>我有一个如下字符串:
10AF101-25
我想提取 - 之前的任何数字编号。并且
在遇到像AF这样的字符串字符时停止
所以我的结果应该是101.
任意帮助表示赞赏。
ge ********* @ gmail.com 写道:
我有一个如下字符串:
10AF101-25
我想提取 - 之前的任何数字。并且
在遇到像AF这样的字符串字符时停止
所以我的结果应该是101.
< snip>
下面的函数可能有所帮助:
函数ScanInt(ByVal T As String)As String
''找到 - "的位置,
''从最后一个字母开始计算
''向后扫描文本,直到
''找到非数字项目
Dim我作为整数
For I = P - 1 To 0 Step -1
如果不是Char.IsDigit(T(I))那么
退出
结束如果
下一页
''我引用第一个非数字字母
I + = 1
如果我< P然后
返回T.Substring(我,P - I)
否则
返回String.Empty
结束如果
结束功能
问候,
B.
这似乎比它需要的复杂得多。为什么当你可以立即将字符串分割到其位置并扔掉你不需要的那个元素时,为什么要搜索 -
?
" Branco Medeiros" < br ************* @ gmail.com写信息
新闻:11 ***************** *****@i42g2000cwa.googlegr oups.com ...
>
ge ********* @ gmail.com 写道:
>我有如下字符串:
10AF101-25
我想提取 - 之前的任何数字。当它遇到像AF这样的字符串字符时停止
所以我的结果应该是101.
< snip>
下面的函数可能会有所帮助:
函数ScanInt(ByVal T字符串)字符串
''查找 - 的位置,
''从最后一个字母开始计算
''向后扫描文本,直到
''找到非数字项目
Dim I As Integer
For I = P - 1 To 0 Step -1
如果不是Char.IsDigit(T(I))那么
退出
结束如果
下一页
''我引用第一个非数字字母
I + = 1
如果我< P然后
返回T.Substring(我,P - I)
否则
返回String.Empty
结束如果
结束功能
问候,
B.
I have a string like the following:
10AF101-25
I would like to extract any numerical number that precedes the "-" and
stops when it encounters any string character like AF
So my result should be 101.
Any help is appreciated it.
Dim x As String = "10AF101-25"
Dim y As String() = x.split("-")
Dim z As String
dim i As Integer
For i = 0 To y(0).length
If IsNumeric(y(i)) Then z = y &= y(i)
Next
<ge*********@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...>I have a string like the following:
10AF101-25
I would like to extract any numerical number that precedes the "-" and
stops when it encounters any string character like AF
So my result should be 101.
Any help is appreciated it.
ge*********@gmail.com wrote:I have a string like the following:
10AF101-25
I would like to extract any numerical number that precedes the "-" and
stops when it encounters any string character like AF
So my result should be 101.<snip>
The function bellow may help:
Function ScanInt(ByVal T As String) As String
''Finds the position of the "-",
''counting from the last char
Dim P As Integer = T.LastIndexOf("-")
''Scans the text backward until
''a non noumeric item is found
Dim I As Integer
For I = P - 1 To 0 Step -1
If Not Char.IsDigit(T(I)) Then
Exit For
End If
Next
''I is referencing the first non-digit char
I += 1
If I < P Then
Return T.Substring(I, P - I)
Else
Return String.Empty
End If
End Function
Regards,
B.
This seems much more complicated than it need be. Why search for the "-"
when you can immediately split the string at its location and throw away the
part you don''t need?
"Branco Medeiros" <br*************@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...>
ge*********@gmail.com wrote:>I have a string like the following:
10AF101-25
I would like to extract any numerical number that precedes the "-" and
stops when it encounters any string character like AF
So my result should be 101.<snip>
The function bellow may help:
Function ScanInt(ByVal T As String) As String
''Finds the position of the "-",
''counting from the last char
Dim P As Integer = T.LastIndexOf("-")
''Scans the text backward until
''a non noumeric item is found
Dim I As Integer
For I = P - 1 To 0 Step -1
If Not Char.IsDigit(T(I)) Then
Exit For
End If
Next
''I is referencing the first non-digit char
I += 1
If I < P Then
Return T.Substring(I, P - I)
Else
Return String.Empty
End If
End Function
Regards,
B.
这篇关于在字符和sysmbol之间进行解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!