removing whitespace from String.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

removing whitespace from String.

rohit
hi i am trying to remove whitespace from string, but have been unable to do so in cases where there are 3 consecutive whitespaces. for eg.

String X = X.replaceAll(" ", "-");

replaces only a maximum of 2 consecutive whitespace and not 3. i tried running the relaceAll, once again on the already modified string, but it did not help.

any ideas will be helpful.

Thanks

Rohit
Reply | Threaded
Open this post in threaded view
|

Re: removing whitespace from String.

Jacques Le Roux
Administrator
Did you try to Google for "java replace all spaces"?

Jacques

From: "rohit" <[hidden email]>

> hi i am trying to remove whitespace from string, but have been unable to do
> so in cases where there are 3 consecutive whitespaces. for eg.
>
> String X = X.replaceAll(" ", "-");
>
> replaces only a maximum of 2 consecutive whitespace and not 3. i tried
> running the relaceAll, once again on the already modified string, but it did
> not help.
>
> any ideas will be helpful.
>
> Thanks
>
> Rohit
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/removing-whitespace-from-String-tp2537234p2537234.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: removing whitespace from String.

Jacques Le Roux
Administrator
Did you find it?
s.replaceAll("\\s+","");Always think regex in such cases: more powerfulJacques
From: "Jacques Le Roux" <[hidden email]>

> Did you try to Google for "java replace all spaces"?
>
> Jacques
>
> From: "rohit" <[hidden email]>
>> hi i am trying to remove whitespace from string, but have been unable to do
>> so in cases where there are 3 consecutive whitespaces. for eg.
>>
>> String X = X.replaceAll(" ", "-");
>>
>> replaces only a maximum of 2 consecutive whitespace and not 3. i tried
>> running the relaceAll, once again on the already modified string, but it did
>> not help.
>>
>> any ideas will be helpful.
>>
>> Thanks
>>
>> Rohit
>>
>> --
>> View this message in context: http://ofbiz.135035.n4.nabble.com/removing-whitespace-from-String-tp2537234p2537234.html
>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: removing whitespace from String.

Jacques Le Roux
Administrator
Not sure why it got so lovely packed :/

Jacques

From: "Jacques Le Roux" <[hidden email]>

> Did you find it?
> s.replaceAll("\\s+","");Always think regex in such cases: more powerfulJacques
> From: "Jacques Le Roux" <[hidden email]>
>> Did you try to Google for "java replace all spaces"?
>>
>> Jacques
>>
>> From: "rohit" <[hidden email]>
>>> hi i am trying to remove whitespace from string, but have been unable to do
>>> so in cases where there are 3 consecutive whitespaces. for eg.
>>>
>>> String X = X.replaceAll(" ", "-");
>>>
>>> replaces only a maximum of 2 consecutive whitespace and not 3. i tried
>>> running the relaceAll, once again on the already modified string, but it did
>>> not help.
>>>
>>> any ideas will be helpful.
>>>
>>> Thanks
>>>
>>> Rohit
>>>
>>> --
>>> View this message in context: http://ofbiz.135035.n4.nabble.com/removing-whitespace-from-String-tp2537234p2537234.html
>>> Sent from the OFBiz - User mailing list archive at Nabble.com.
>>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: removing whitespace from String.

rohit
In reply to this post by Jacques Le Roux
hi Jacques,

Yes, i found the same code as you mentioned and it did work.

thanks so much.

rohit