Click here to Skip to main content
15,888,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

Use the substring method [^].
 
Share this answer
 
v2
C#
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;
}
 
Share this answer
 
v2
Get some idea from following link
http://www.dotnetperls.com/substring[^]
 
Share this answer
 
Hello,

Substring is used if you want to extract a small portion out of the main string.

Suppose i have a string say s= "abc"; // if you say
s.Substring(start_location,number_elements_you_want);

Look at the below code:


C#
while (true)
           {
               Console.WriteLine("Enter a string");
               string s;
               Console.WriteLine("The string you entered was : {0}", s = Console.ReadLine());
               int loc; int length;
               Console.WriteLine("Enter the starting location of the substring and the number of charecters in it");
               Console.WriteLine(" the starting location :{0}, length:{1}", loc = int.Parse(Console.ReadLine()), length = int.Parse(Console.ReadLine()));
               Console.WriteLine("The resultant is : {0}", s.Substring(loc, length));
               Console.ReadLine();


           }




Thanks,
Rahul
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900