Sunday, September 03, 2006

C++ note: about strings

length - s.length() / s.size()
index - s[1] = 'x' / s[2]
slice - s.substr(1,4) means starting from 1, length 4.
append - s.append(t)
replace - s.replace(1,3, 'x') replaces slice (1,3)
erase - s.erase(1,2) same meaning
find - s.find("abc",2) find from index 2
reverse - reverse(s.begin(), s.end()) modifies strs.

It's alright concatenating strings with +
The constructor can also be s = string(t, start, length).

No comments: