locked
string manipulation RRS feed

  • Question

  • User850175837 posted
    hi friends

        can u please tell me how can i search a string in a line of text

    my problem is "hello   print value"

    result:
            display only left side of print ie "hello"

    can u plz suggest me

    Regards

    Prakash Patil
    Tuesday, August 23, 2005 2:09 AM

All replies

  • User-1041436249 posted

    Prakash,

    Please see whether the following helps you:

    ------------------------------------------------------------------------
    using System;

    public class StringExtract
    {
       public static void Main(string[] args)
       {
           try
           {
             string strHostString = "hello   print value";
             string strToSearch = "hello";

             Console.WriteLine("The search value is "+strHostString.Substring(strHostString.IndexOf(strToSearch),strToSearch.Length));
            }
            catch (Exception ee)
            {
                 Console.WriteLine(ee.ToString());
            }
       }
    }
    ------------------------------------------------------------------------


    Moderator: Can you move the original thread and this (associated) reply to General ASP.NET discussions or is ok in the code samples itself?
    Tuesday, August 23, 2005 2:59 AM