Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Ignore case strings (http://www.go4expert.com/forums/ignore-case-strings-t3824/)

shah123 10Apr2007 19:36

Ignore case strings
 
when enter the text to find the string i want to ignore the case how to implement that in a context below
Code:

public override void Search()
        {
           
            //file = new FileStream(@"C:\username.txt", FileMode.Open, FileAccess.Read);
           
            Console.WriteLine("Input a string ");
            String data = Console.ReadLine();
            sr = File.OpenText(@"C:\username.txt");
            String st = sr.ReadToEnd();
          // How to implement ignore cases
           
                if (st.Contains(data))
                {
                    Console.WriteLine("Found at position :" + st.IndexOf(data));
                }
                else
                {
                    Console.WriteLine("Not Found");
                }

Thanks,

shabbir 10Apr2007 19:39

Re: Ignore case strings
 
Use CompareNoCase
or convert both of them to Lower/Upper case before using the contains.

shah123 10Apr2007 19:45

Re: Ignore case strings
 
How to put CompareNoCase in this method?

shah123 10Apr2007 20:36

Re: Ignore case strings
 
Any help?

shabbir 10Apr2007 21:43

Re: Ignore case strings
 
I made an error CompareNoCase is for CString of C++ and not for C# but its CompareTo and I guess the best option is to make each of them to the same case.

shah123 10Apr2007 21:54

Re: Ignore case strings
 
Thanks Shabbir for this but i got one solution on my own but now as Search functionality works i have something same in switch cases


Code:

String s;
                s = Console.ReadLine();
               
               
                switch (s)
                {
                    case "g":
                        Console.Clear();
                        uname.getUserName();
                        return choices();
                      // break;

if i want to enter "G" it doesnt accept how to do that?

shabbir 11Apr2007 09:17

Re: Ignore case strings
 
2 Options.
Have a case Fall Through with "G" and g like the one below.
Code:

String s;
s = Console.ReadLine();
switch (s)
{
        case "g":
        case "G":
                Console.Clear();
                uname.getUserName();
                return choices();
          // break;

or convert the s to the lower case with ToLower.

shah123 12Apr2007 14:22

Re: Ignore case strings
 
Thanks a million, Shabbir. It worked for me. Now i will continue on how to delete a line from the text file. I will do separate thread at some stage.


All times are GMT +5.5. The time now is 00:00.