解析整数字符串,其中包含字母和空格 - C# [英] Parse integer from string containing letters and spaces - C#

查看:152
本文介绍了解析整数字符串,其中包含字母和空格 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是解析一个整数出含有字母和空格的字符串的最有效方法是什么?

What is the most efficient way to parse an integer out of a string that contains letters and spaces?

例: 我通过了以下字符串:RC 272。我想从字符串检索272。

Example: I am passed the following string: "RC 272". I want to retrieve 272 from the string.

我使用C#和.NET 2.0框架。

I am using C# and .NET 2.0 framework.

推荐答案

由于字符串的格式将不会改变 KISS < /一>:

Since the format of the string will not change KISS:

string input = "RC 272";
int result = int.Parse(input.Substring(input.IndexOf(" ")));

这篇关于解析整数字符串,其中包含字母和空格 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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