c# - char.IsWhiteSpace finds space at "wrong" position -
i working through book on sample code got bit confused , struggle find (probably simple) answer. wrote following code:
static void charfunctionality() { console.writeline("char.iswhitespace('hello there', 5): {0}", char.iswhitespace("hello there", 5)); console.writeline("char.iswhitespace('hello there', 6): {0}", char.iswhitespace("hello there", 6)); console.writeline(); console.readkey(); }
when run following output:
char.iswhitespace('hello there', 5): true char.iswhitespace('hello there', 6): false
i think should other way around? 5th character 'o' , 6th 'space'. hope can point me in right direction on journey world of development :)
thank you!
the number provide index of letter in string want for. in first case, letter in 5th index of strong. in c#, indexes (for arrays or strings, doesn't matter) start @ index 0.
so in string "hello there", 'h' in index 0, 'e' in index 1, 'l' in index 2, etc. means char in 5th index white space.
this works way in programming languages. must start counting @ 0.
Comments
Post a Comment