Thursday 15 January 2015

C# string manipulation ideas request -



C# string manipulation ideas request -

i can't seem find 'good' way go doing task string

say if have string, value "take chocolate" , observe if string has string "cola", in it, using .contains method, , contain "cola" in it. want way programme character before 'c' in "cola" , character after 'a', check if characters both empty spaces. ideas how tackle problem? tips or ideas fantastic!

p.s. making quite extensive text-based adventure game.

static void main(string[] args) { string s = "take chocolate"; string searchstring = "cola"; int beginindex = 0; int endindex = 0; if (s.contains(searchstring)) { beginindex = s.indexof(searchstring, 0, s.length); endindex = beginindex + searchstring.length; } if(endindex < s.length) { console.writeline(s[endindex + 1]); } else { console.writeline("there no character after" + searchstring); } if(beginindex > 0) console.writeline(s[beginindex - 1]); else console.writeline("there no character before" + searchstring); }

here little programme doing this. hope helps.

c# string

No comments:

Post a Comment