Use boost string algorithms, they work