Michael Winter wrote:
[color=blue]
> On Sat, 18 Dec 2004 12:19:08 +0100, VK <schools_ring@y ahoo.com> wrote:
>
> Please include quotes from the previous post.
>[color=green]
>> if (myString.index Of(' ') != -1) {
>> /* your code */
>> }[/color]
>
>
> If the OP is trying to check if a space is between characters wouldn't
> the index need to be one or greater?[/color]
No. !1 = -1 means it was found in the string. But that doesn't satisfy
the OP's requirements:
' myStringWithOnl yALeadingSpace'
Passes that test but has no space "between" characters.
VK wrote:[color=blue]
> Oh come on, guys...
>
> The OP said (adjusting the grammar) : "how to find if a string has at least
> one space between its characters"
>
> if (myString.index Of(' ') != -1) {
> /* your code */
> }
> gives the right answer: yes, it does.[/color]
No, it doesn't give the right answer. Test the following two strings:
myString = " String1"
myString = "String2 "
Both have spaces, both will pass the test, but neither has "at least one
space *between* characters".
A third, more obvious, example of failure is this:
myString = " "
What characters is that space between?
<--snip-->
And please, in the future, quote what you are replying to.
Comment