String Format Help!
-
I have a log that outputs a line like this; BATTERY VOLTAGE RESTORED Note the blank(whitespace) after the word RESTORED, and then an odd Ascii character at the end. I need to eliminate everything after the word restored and terminate the line at that point. Thanks,
-
I have a log that outputs a line like this; BATTERY VOLTAGE RESTORED Note the blank(whitespace) after the word RESTORED, and then an odd Ascii character at the end. I need to eliminate everything after the word restored and terminate the line at that point. Thanks,
You could iterate through the characters in the string L-R and check the ASCII code of each character. As soon as you find a character whose ASCII code is outside of a certain range e.g. not a letter or number, return a string containing all the characters up to but not including that character. Alternatively, if you know that only the last character isn't needed, use
String.Substring
to return a string that contains every character in a line minus the last character.Paul Marfleet
-
You could iterate through the characters in the string L-R and check the ASCII code of each character. As soon as you find a character whose ASCII code is outside of a certain range e.g. not a letter or number, return a string containing all the characters up to but not including that character. Alternatively, if you know that only the last character isn't needed, use
String.Substring
to return a string that contains every character in a line minus the last character.Paul Marfleet
The problem with the L-R is that the ASCII is a random generated item. Not consistant for each entry. I didn't think about the string.substring method. I will have to give that a look. Thanks,
-
The problem with the L-R is that the ASCII is a random generated item. Not consistant for each entry. I didn't think about the string.substring method. I will have to give that a look. Thanks,
-
By L-R I mean process the string contents from left to right. Check each character until you find one whose ASCII code that isn't valid for your purposes. Consult a table of ASCII codes to determine what the valid ranges might be.
Paul Marfleet
Got it. I think I can mangle it from here!