如何获得在C#中的字符串的子串? [英] How to get substring from string in c#?

查看:157
本文介绍了如何获得在C#中的字符串的子串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的字符串,其存储在一个字符串变量str中。我想从C#中获取子串?
假设字符串为:从此实例检索子子串开始于指定字符位置。

I have a large string and its stored in a string variable str. And i want to get a substring from that in c#? Suppose the string is : " Retrieves a substring from this instance. The substring starts at a specified character position."

子串的结果是什么,我想显示为:子串开始于指定字符位置

Substring result what i want to display is: The substring starts at a specified character position.

推荐答案

您可以手动或使用的IndexOf 办法做到这一点。

You could do this manually or using IndexOf method.

手动

int index = 43;
string piece = myString.Substring(index);



使用的IndexOf,你能看到的句号是:

Using IndexOf you can see where the fullstop is:

int index = myString.IndexOf(".") + 1;
string piece = myString.Substring(index);

这篇关于如何获得在C#中的字符串的子串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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