jose said:
Hi,
Does any know a algorithm to strip heading and leading blank in a string ?
as long as the string has not size 0 and the first character of
the string is blank {
remove first character from string
}
as long as the string has not size 0 and the last character of the
string is blank {
remove last character from string
}
Of course variations are possible (as always: there is more then
one way to skin a cat)
n = 0;
as long as n is not greater then the length of the string and
the n-th character is blank {
n = n + 1
}
// n now contains the number of heading blank characters
remove the first n characters from the string
n = length of string
as n is greater or equal to 0 and n-th character is blank {
n = n - 1
}
// n now contains the number of trailing blank characters
remove the last n characters from the string
instead of removeing characters from a string one could also
create a substring which contains all but the characters to
remove. Which brings us to another variation:
count the number of heading blank characters -> n
count the number of trailing blank characters -> m
extract a substring which contains all but the first n and
the last m characters.
....