0

hi all ,

i want to make function that remove any space before sentance
(i.e if user enter multi space before your comment remove it )
and if enter multi space only this function return empty string .

4
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by Ezzaral
0

good luck with that... once you've written some code, don't get the result you want and don't know where the problem lies, just submit your code and the error you get.
but, like you said it: YOU want to make that function

need some pointers? an easy way to do it is using a very simple String object in which you store your text, and using the indexof() and substring() methods.

0

thanks ,

my function worked correct wher i make that
String str = " amtallah ";
String trimmedStr = str.trim()

0

What the prvious poster was saying is, post the method you are using, as well as the code where you get the string from the user, and where you then call the method involved.

0

So you solved your issue or you still have a question? You haven't actually made a function there - just used an existing String function, but perhaps that is all you needed to do?

Note that if you are trimming input from a text box, you will want to first make sure that the string is not null as well

String inStr = aTextField.getText();
if (inStr != null)
  inStr = inStr.trim();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.