Re: problem with split method
- From: Daniel Kirsch <Iwillnotread_daniel@xxxxxx>
- Date: Wed, 22 Feb 2006 11:13:55 +0100
Daniel Kirsch wrote:
Roy - Topup Communications wrote:Hi, I have to check strings in a text area, there are spaces between each string and I used split method to sort the array. anyhow,it doesn't work with spaces, only with (,). how can i work it out?
Works for me:
alert("this is a test".split(" ").length)
If you want to recreate the string from the sorted array, use the array's join method and pass the character you want as parameter:
alert("this is a test".split(" ").sort().join(" "));
You may create a small function to do the job and some checkings:
function sortString(str,delimiter) {
if (typeof str != "string") return str;
if (typeof delimiter != "string") delimiter = " ";
return str.split(delimiter).sort().join(delimiter);
}
Daniel
.
- References:
- Re: problem with split method
- From: Daniel Kirsch
- Re: problem with split method
- Prev by Date: Re: problem with split method
- Next by Date: Re: GetElements of TD
- Previous by thread: Re: problem with split method
- Index(es):
Relevant Pages
|