CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: IndexOfAny

  1. #1
    Join Date
    Mar 2010
    Posts
    15

    IndexOfAny

    Hello,

    I am in the midst of building a program that will parse a giant file down to what I need. So I read in hundreds of lines, I then assign the appropriate lines to an array. I then need to look through each line in the array and figure out positioning because the material I am looking for is embedded within a bunch of garbage. I am able to figure this out by looking for the first instance of the "<" character and the second instance of the ">" character.

    So I used IndexOf to find the first index number which worked perfectly. I then want to use the IndexOfAny with additional I believe overloads, one of the character "<" and of a starting index to prevent looking at the first instance of "<".

    Here is what I got...


    Code:
                string specialCharacterStringOne = ">";
    
    
                char[] specialCharacterStringTwo = new char[1];
    
                specialCharacterStringTwo[0] = '<';
    
                for (g = g; g != z; g++)
                {
                    int specialCharacterOne = outputFile2[g].IndexOf(specialCharacterStringOne);
                    int specialCharacterTwo = outputFile2[g].IndexOfAny(specialCharacterStringTwo[0], specialCharacterOne);
    
                }
    Unfortunately it doesn't like my IndexOfAny and throws the following errors:

    Error 4 The best overloaded method match for 'string.IndexOfAny(char[], int)' has some invalid arguments

    Error 5 Argument '1': cannot convert from 'char' to 'char[]'

    I figured by doing "char[] specialCharacterStringTwo = new char[1];" I would bypass this cannot convert from 'char' to 'char[]' but that doesn't seem to be working and I am now lost.

  2. #2
    Join Date
    Mar 2010
    Posts
    15

    Re: IndexOfAny

    Now I feel like an idiot....this appears to have corrected it.

    Code:
    int specialCharacterTwo = outputFile2[g].IndexOfAny(new char[] {specialCharacterStringTwo[0]}, specialCharacterOne);

  3. #3
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: IndexOfAny

    Quote Originally Posted by tomtom1923 View Post
    Now I feel like an idiot....this appears to have corrected it.

    Code:
    int specialCharacterTwo = outputFile2[g].IndexOfAny(new char[] {specialCharacterStringTwo[0]}, specialCharacterOne);
    Since the method expects an array of chars, you could also have done this:

    Code:
    int specialCharacterTwo = outputFile2[g].IndexOfAny(specialCharacterStringTwo, specialCharacterOne);
    It's not a bug, it's a feature!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured