Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have string as "1234|5678|2345|Hello World|43456|45345|5345"
when i split this string with | character

it will return
1234
5678
2345
Hello

but i want it as

1234
5678
2345
Hello World
43456
45345
5345
Posted
Comments
thatraja 5-Sep-14 4:27am    
share your code

The following works fine :
JavaScript
var s = "1111|2222|hello there|99999";
var o = s.split("|");
console.log(o);

and you get :
["1111", "2222", "hello there", "99999"] 
 
Share this answer
 
Comments
Devraj Kapdi 5-Sep-14 5:02am    
thank you
Check whether you are using limit parameter value in split function to limit the number of splits

JavaScript
<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var str = "1234|5678|2345|Hello World|43456|45345|5345";
    var res = str.split("|").join("<br/>");
    document.getElementById("demo").innerHTML = res;
}
</script>


OutPut:
1234
5678
2345
Hello World
43456
45345
5345
 
Share this answer
 
v2
Comments
Devraj Kapdi 5-Sep-14 5:02am    
thank you
Dilan Shaminda 5-Sep-14 6:06am    
welcome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900