字符串的子字符串数值 [英] substring numeric value of a string

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

问题描述

大家好,


我需要你专家的帮助。我需要提取字符串的数值。


for ext:string str =" 1234 absc st"或者它可以是123 hello world

或1234567 asp.net



我怎么才能得到数字部分字符串?


请帮助并给我一些建议。


谢谢,

解决方案

一种可能的方法是遍历字符串中的每个字符,并检查它是否为数字。如果是,请将其添加到临时字符串,然后返回该字符串。我不确定这是多么有效。


正则表达式可能对此有用。


我不好自己使用RegEx,所以我不能给你一个样本,但也许其他人可以帮忙。


你好


你总是在字符串上的数值后面找到一个空格。所以它很简单,首先你找到空间的位置,然后你就可以使用子串复制你的数值。


问候

chel-1

Hi all,

I need some help from you expert. I need to extract numeric value of a string.

for ext: string str = "1234 absc st" or it can be "123 hello world"
or "1234567 asp.net"


How can i only get the numeric part of the string?

Please help and give me some suggestions.

Thank you,

解决方案

One potential way would be to go through each char in the string, and check if it''s numeric. If it is, add it on to a temporary string, which is then returned. I''m not sure how efficient this is however.


Regular expressions would probably be useful for this.

I''m not good with RegEx myself, so I can''t give you a sample, but maybe someone else can help with that.


hi

you always find a space after your numeric value on your string. so its simple, first you find the position of the space , then you able to copy your numeric value by using substring.

regards
chel-1


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

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