c# - 从字符串 C# 中查找并提取一个数字
问题描述
我需要查找并提取字符串中包含的数字。
例如,从这些字符串:
“O:2275000 BF:3060000 D:3260000 E:3472000 I:3918000 T:4247000 UF:4777000 A:4904000 AD:5010000 X:5243000 G:21280000”
提炼 :
1.2275000 2.3060000 3.3260000 ....
解决方案
这将是 :
string temp = yourText;
List<int> numbers = new List<int>();
Regex re = new Regex(@"\d+");
Match m = re.Match(temp);
while (m.Success)
{
numbers.Add(Convert.ToInt32(m.Value));
temp = temp.Substring(m.Index + m.Length);
m = re.Match(temp);
}
推荐阅读
- python - 用 Python 实现派生类,而用 C++ 编写基类
- java - Keycloak Java:让所有成员加入 GroupModel
- shell - 如果一列的值等于上一行中同一列的值加一,则给出相同的代码
- java - 一起运行所有测试时,某些单元测试会失败 Spring boot
- python - 比较和过滤 2 个文件
- python - Django FileNotFound 图片网址
- azure-functions - 无法将“用户管理的标识”与 Azure Function App 一起使用
- python - 通过迭代每一行并使用结果输出创建新列来注释最大值
- django - 如何在不重新加载页面的情况下更新包含查询集的下拉列表
- firebase - 将 Firebase 上的 EMAIL_EXISTS 错误代码更改为其他代码