-
April 19th, 2010, 03:50 PM
#1
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.
-
April 19th, 2010, 03:56 PM
#2
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);
-
April 20th, 2010, 02:04 AM
#3
Re: IndexOfAny
Originally Posted by tomtom1923
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|