.net - Vb.net 仅从带整数的字符串中获取整数

我有这个字符串 123abc123 我怎样才能从这个字符串中只得到整数?

例如,将123abc123转换为123123

我尝试了什么:

Integer.Parse(abc)

最佳答案

你可以使用 Char.IsDigit

Dim str = "123abc123"
Dim onlyDigits = New String(str.Where(Function(c) Char.IsDigit(c)).ToArray())
Dim num = Int32.Parse(onlyDigits)

https://stackoverflow.com/questions/13186753/

相关文章:

vba - 如何获取表单的最后一条记录ID?

awk - 如何删除文本文件中的重复单词

php - .htaccess url 编码字符串未正确传递到页面

php - 如何使用php删除重复的字母

php - 使用单个命中的唯一文档 ID 通过 Amazon CloudSearch 搜索数据

delphi - 如何在 Delphi XE3 中将 String 转换为 LongInt?

php - 在 Symfony 中禁用错误​​页面

.net - 如何避免评估所有 'iif' 表达式?

matlab - 根据经纬度获取大陆

php - 为什么 PhpStorm 检查说 `Exception` 未定义?