将文本内容放入数组中

smypolice 2013-06-13 10:20:10
本人想将文本文档的内容,放入字符串数组中。
文本内容格式:数字(空格)数字(空格)数字(空格)数字
数字(空格)数字(空格)数字(空格)数字
数字(空格)数字(空格)数字(空格)数字
~~~~~~~
如何只提取数字放入数组?
用正则表达式呢?
...全文
101 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
用split 就可以了
bdmh 2013-06-13
  • 打赏
  • 举报
回复
正则就行了

            int[] arr;
            string str = @"20 5231 214 55";
            string strmatch = @"[\d]+";
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch);
            System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str);
            arr = new int[mc.Count];
            for (int i = 0; i < mc.Count; i++)
            {
                arr[i] = Convert.ToInt32(mc[i].Value);
            }
shawn_yang 2013-06-13
  • 打赏
  • 举报
回复
string[] abcd= str.split("");
iceMung 2013-06-13
  • 打赏
  • 举报
回复
string.split

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧