只读文本文件中的整数 [英] Read only integers froma text file

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

问题描述

你好

我的问题是说我在文本文件中有一个名称为"test.txt"的文本文件,它具有"1ab2n3",首先我想从文本文件中仅读取整数(123),然后其余字符即(abn)是可能的第二个方法是我尝试了很多东西file.Io.readalllines etc

Hello

my question is lets say i have a text file with a name "test.txt" inside text file it has "1ab2n3"first i want to read only integers(123) from text file,then the remaining character i-e(abn)Is it possible secondly how to do it i have tried so many things file.Io.readalllines etc

推荐答案


您可以使用RegEx提取数字和/或字符串.
尝试以下代码

Hi ,
You can use RegEx to extract the number and/or string.
Try following code

string myStr = "1ab2n3";

string myNumberResult = Regex.Replace(myStr, @"[^\d]", "");
            
                
string myCharResult = Regex.Replace(myStr, @"[\d]", "");



希望能有所帮助.如果是这样,请将其标记为答案/赞.
-Milind



Hope that helps. If it does, mark the it as answer/upvote.
-Milind


查看此链接,您可能会知道
http://stackoverflow.com/questions/1968328/read-数字来自C锐利的文本文件 [
see this link you may get idea
http://stackoverflow.com/questions/1968328/read-numbers-from-a-text-file-in-c-sharp[^]


这篇关于只读文本文件中的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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