得到一串数字? [英] Get a string of number ?

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

问题描述

我有一个字符串abcd 36.2如何仅获取36.2的值,可以更改abcd吗?

i have a string abcd 36.2 How to get the value 36.2 only , with abcd can be changed?

推荐答案

dec82;

您可以使用正则表达式提取数字数据.

Hi dec82;

you could use a regular expression to pull the numeric data out.

<br />        '' Test data<br />        Dim testData As String = "abcd 36.2"<br />        '' String to hold the wanted info<br />        Dim numericValue As String = String.Empty<br />        '' A regular Expression to pull out the needed info<br />        Dim m As Match = Regex.Match(testData, "^.*?(\d+(?:\.\d+)?)")<br />        '' Test to see if the string had a numeric value on the end of it<br />        If m.Success Then<br />            '' Pull out the information<br />            numericValue = m.Groups(1).Value<br />        End If<br /><br />        MessageBox.Show("Numeric Value = " & numericValue)<br />



Fernando



Fernando


您好,一个选项是可以循环遍历整个字符串并检查数字
,即.

Hi
one option is that you can loop through the entire string and check for numerics
ie.

Dim x As String = "abcd 36.2"<br />            Dim value As String = ""<br />            For lp As Integer = 0 To x.Length - 1<br />                If IsNumeric(x.Chars(lp)) Or x.Chars(lp) = "." Then<br />                    value &= x.Chars(lp)<br />                End If<br />                Application.DoEvents()<br />            Next<br />            MsgBox(value)



希望这会有所帮助
Anoop



hope this helps
Anoop


这篇关于得到一串数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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