C# string need to search for a lack of < & >
-
Hi All, Question I have a string of Data that I am going to split with the method :
string[] Values = FileData.Split(delimeterCharFurther);
delimeterCharFurther are
char[] delimeterCharFurther = { '<', '>' };
I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable
for (int a = 0; a <= FileData.Length; a++)
{
Location = FileData.IndexOf("><");
MessageBox.Show(Location.ToString());}
but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following
-
Hi All, Question I have a string of Data that I am going to split with the method :
string[] Values = FileData.Split(delimeterCharFurther);
delimeterCharFurther are
char[] delimeterCharFurther = { '<', '>' };
I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable
for (int a = 0; a <= FileData.Length; a++)
{
Location = FileData.IndexOf("><");
MessageBox.Show(Location.ToString());}
but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following
IndexOf is overloaded, therefore
location=string.IndexOf(subString, location+1);
if often used in a loop for such purposes. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Hi All, Question I have a string of Data that I am going to split with the method :
string[] Values = FileData.Split(delimeterCharFurther);
delimeterCharFurther are
char[] delimeterCharFurther = { '<', '>' };
I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable
for (int a = 0; a <= FileData.Length; a++)
{
Location = FileData.IndexOf("><");
MessageBox.Show(Location.ToString());}
but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following
Hi Glenn, Not sure what 'valid' means : what about "<a<b>>" ?? you should get "a","b" If so 'split' is probably not the path to the solution. But if not (i.e. <a<b>> is invalid ) why not
string[] Values = FileData.Split('<');
first then check values that are ending with a '>' Regards
-
Hi Glenn, Not sure what 'valid' means : what about "<a<b>>" ?? you should get "a","b" If so 'split' is probably not the path to the solution. But if not (i.e. <a<b>> is invalid ) why not
string[] Values = FileData.Split('<');
first then check values that are ending with a '>' Regards
Thanks for that, I think 'valid' was my typing as thinking the data is (should be) enclosed in < & > but in transmission some times it shows up as Data not (or even D!"" random ASCII) if it does throw 'em away and carry on. My think was along the lines of declare an int pointer increment over the string, then I remembered it was Windows and C#, not DOS & Turbo C!! Glenn
-
Hi All, Question I have a string of Data that I am going to split with the method :
string[] Values = FileData.Split(delimeterCharFurther);
delimeterCharFurther are
char[] delimeterCharFurther = { '<', '>' };
I need to check the string before I split it that all the valid data is surrounded by < and >. I was thinking of a variable
for (int a = 0; a <= FileData.Length; a++)
{
Location = FileData.IndexOf("><");
MessageBox.Show(Location.ToString());}
but if I'm right that will only find the first, one way to do it I'm guessing is to search for a > without a following
Or use a Regular Expression:
@"<(?'Data'[^>]*?>"