Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
02-01-2014, 03:55 AM #1
- Join Date
- Feb 2012
- Thanked 0 Times in 0 Posts
Lost at where to go with a problem I need to salve?
I have to make a method that allows you to enter a string as a parameter, and then it removes all unnecessary output.
I have no idea where to go on this I am not allowed to use the trim method that is built in.
String str = " I like pie "
String after method call
"I like pie"
02-03-2014, 05:37 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,668 Times in 2,637 Posts
If you can't use trim, I'd presume you're not familiar with regex either. Also assuming that only the first or last chars being whitespace are relevant, you can simply iterate the chars in the string, and append them to another string after checking the char.
The easiest way I can think of is to iterate the string up to string length or until a non-whitespace char is found (Character.isWhitespace can be used for this), which will give you the starting position of the first char that's not whitespace, then do the same thing but from the end of the string back to get the first non-whitespace char from the end. Then you simply make use of the String .substring method.PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');