Hi everybody,
I have this:
[code]
function splitButtonPressed()
{
var inputString = document.getElementById("inputVal").value;
var tokens = inputString.split(" " + "\n");
document.getElementById("output").value = inputString.replace(/\s+/g, ' ', "\n");
document.getElementById("ouput").value = tokens.indexOf(inputString);
}
document.getElementById("outputSubstring").value = inputString.substring(0, 10);
// end function splitButtonPressed
// -->
[/code]
But now for example I type: 33 88, then output ---> 33 88. But it has to be:
33
88
So the extra space is will be omitted, but it is still one the same row and not under each other How to manage that?
Thank You.
Loading
albert albertPosted Oct 25, 2013, 6:56 AM
albert albertPosted Oct 25, 2013, 6:19 AM
hello this is a nice language. then the output has to be:
hello
this
is
a
nice
language
Thanks
Jignesh TrivediPosted Oct 25, 2013, 6:07 AM
your string has value like " 33 88" right. after the spliting the value you got the 33 and 88 right?
here from the first varible you can get 33 and from last variable you can get 88.
also you can use these variable whenever you required...
this code remove your extra spece problem.
hope this will help you.
albert albertPosted Oct 25, 2013, 6:03 AM
I have it now like this:
[code]
function splitButtonPressed()
{
var inputString = document.getElementById("inputVal").value;
//var tokens = inputString.split(" " + "\n");
var tokens = inputString.split(" ");
var first = token[0];
var last = token[token.length - 1];
document.getElementById("output").value = inputString.replace(/\s+/g, ' ', "\n");
document.getElementById("ouput").value = tokens.indexOf(inputString);
}
document.getElementById("outputSubstring").value = inputString.substring(0, 10);
// end function splitButtonPressed
[/code]
But how to use the first and last?
Jignesh TrivediPosted Oct 25, 2013, 12:35 AM
hi,
i think split function does not find any new line charater in your string....
you can do just like
var tokens = inputString.split(" ");
var first = token[0];
var last = token[token.length - 1];
hope this will help you.