首页 > 生活

正则表达式找数字

更新时间:2025-05-16 02:03:28 阅读: 评论:0

倪海厦去世跳转至专题目录

档案袋设计专题推荐文章:localPosition与anchoredPosition转化 unity Scene View扩展之编辑器扩展总结 using System.Collections;using System.Collections.Generic;using UnityE农村故事n溢脂性脱发gine;using System.Text.RegularExpressu盘读不出来ions;p好听的群名ub考试周刊lic class RegexNum : MonoBehaviour{public string input;public char separator;private Dictionary<int, string> mapNumDesc;void Start() {mapNumDesc = new Dictionary<int, string>();}private void OnGUI(){if (GUI.Button(new Rect(0, 0, 100, 50), "Find")){Find();DumpDict();}}private void Find(){var partList b级成绩查询= input.Split(sepa祛痘的护肤品rator);for (i早稻nt i = 0; i < 死亡颂唱者partList.Length; 初中毕业学什么好i++){int result = -1;string str = partList[i];Debug.Log(i + " "testflight + result + " " + str + " Bian Li");if (string.IsNu平安保险怎么样llOrEmpty(str)){continue;}Match match = Regex.Match(str, @"\d");if (match != null){result = int.Parse(match.Value);if (result > 0){Debug.Log(i + " " + match.Value + " 网上免费赚钱 " + str + " result");mapNumDe电影盲井sc[result] = str;}}}}private void DumpDict(){Debug.Log("---------------------------------------贝奥武夫----------------------");foreach (var item in mapNumDesc){Debug.Log(string.Format("Key:{0} Value:{1}&#南京银行信用卡34;, item.Key, item.Value));}Debug.Log("-------------------------------------------------------------");}}

需求:

输入字符串,如“1:你好;2:我好;3:他好”,输出字典

Key:1飞跃颠峰 Value:"1:你好"

Key:2 Value:"2:我好"

Key:3 Value:"3:他好"

可扩展:

1、多位数

2、正负数,小数,分数等带符号的数

3、字符

4、Key不是第一个数字,比如说:“1:2个考研辅导班”,找出来的Key为2

最新代码见github中的RegexNum场景

本文发布于:2023-06-02 07:59:13,感谢您对本站的认可!

本文链接:http://www.ranqi119.com/ge/85/188223.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数字   正则表达式
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 站长QQ:55-9-10-26|友情:优美诗词|电脑我帮您|扬州装修|369文学|学编程|软件玩家|水木编程|编程频道