如何从字符串中获取子字符串 [英] How to get a substring from a string

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

问题描述

如何在不使用正则表达式的情况下从字符串中获取子字符串



例如:

如果我有一个字符串:



string string1 = HH28_27.pdf,abc.doc,xyz.txt



谢谢和问候,

AAA



http://www.google.com/



来自这个字符串'string1',我需要的输出是



string1 = HH28_27.pdf,abc.doc,xyz.txt

解决方案

使用 substring 方法 [ ^ ]。


  protected   void  Button1_Click( object  sender,System.EventArgs e)
{
string myString = TextBox1.Text.ToString();
string subString = myString.Substring( 0 5 );
Label1.Text = 子串[0,5]: + subString;
}


从以下链接中获取一些想法

http://www.dotnetperls.com/substring [ ^ ]

How to get a substring from a string without using Regex

For eg:
if i got a string like:

string string1=HH28_27.pdf,abc.doc,xyz.txt

Thanks and Regards,
AAA

http://www.google.com/

from this string 'string1', the output i need'd is

string1=HH28_27.pdf,abc.doc,xyz.txt

解决方案

Use the substring method [^].


protected void  Button1_Click(object sender, System.EventArgs e) 
{
    string myString=TextBox1.Text.ToString();
    string subString=myString.Substring(0,5);
    Label1.Text="Substring[0,5]: "+ subString;
}


Get some idea from following link
http://www.dotnetperls.com/substring[^]


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

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