Hi..
I have given a string input as h="Hello:world". I want to divide the sitring as "Hello" and "world".. I have divided the string with ":" Plz help me how to do this....
Input as
~~~~~~
h="Hello:world";
Output as
~~~~~~~
h1="Hello"
h2="world"
I need the javascript code for this... Help me
Thanks in advance...
Reg
Inba
2 1746
Hi pal
maybe this will help you
or did u wanted to create an array of words? -
<html>
-
<!-- Created on: 10-4-2007 -->
-
<head>
-
<title></title>
-
<script language="JavaScript1.2">
-
//the string
-
var mystring = 'Is this what u ment? peace to u :)';//make sure there is no space at beginning of the string
-
//set a seperator or leave empty
-
var Seperator='<br>';
-
function test1(){
-
//if the string is emmpty do nothing
-
if (mystring=='' || mystring==' '){/*alert ('mystring is empty');*/}
-
else {
-
//get the first space
-
getspace=mystring.indexOf(' ')+1;
-
//if there is no space left , we assume it is the last word
-
if (getspace==0){
-
//get the remaining string length
-
xxx=mystring.length;
-
//read the string from first char to its last
-
firstword=mystring.substring(0,xxx);
-
//read from position xxx to it remaining length *** seems useless but its needed
-
newstring=mystring.substring(xxx,mystring.length);
-
//write the firstword to span
-
InfoSpan.innerHTML+=' '+firstword;
-
//make sure mystring is empty
-
mystring='';
-
}else{
-
//if there is a space left ,read the string from the first char to the first space
-
firstword=mystring.substring(0,getspace);
-
//then write it to span
-
InfoSpan.innerHTML+=' '+firstword+Seperator;
-
//read the string from the first space to the end and assign it to newstring
-
newstring=mystring.substring(getspace,mystring.length);
-
}
-
//set the remaining string as mystring
-
mystring=newstring;
-
//call function test2
-
test2();
-
}
-
}
-
//test2 is the same as test1 :)
-
function test2(){
-
if (mystring=='' || mystring==' '){/*alert ('mystring is empty');*/}
-
else {
-
getspace1=mystring.indexOf(' ')+1;
-
if (getspace1==0){
-
xxx=mystring.length;
-
Secondword=mystring.substring(0,xxx);
-
newstring=mystring.substring(xxx,mystring.length);
-
InfoSpan.innerHTML+=' '+Secondword;
-
mystring='';
-
}else{
-
Secondword=mystring.substring(0,getspace1);
-
InfoSpan.innerHTML+=' '+Secondword+Seperator;
-
newstring=mystring.substring(getspace1,mystring.length);
-
}
-
mystring=newstring ;
-
test1();
-
}
-
}
-
</script>
-
</head>
-
<body>
-
<span id="InfoSpan" ></span><br><br>
-
-
<a onclick="test1()" style="cursor:pointer;text-decoration:underline;">try me</a>
-
</body>
-
</html>
-
peace
Hi pal
maybe this will help you
or did u wanted to create an array of words?
Just ignore my previuos post :) -
<html>
-
<!-- Created on: 10-4-2007 -->
-
<head>
-
<title></title>
-
<script language="JavaScript1.2">
-
//the string
-
var mystring = 'Is this what u ment? peace to u :)';//make sure there is no space at beginning of the string
-
//set a seperator or leave empty
-
var Seperator='<br>';
-
function test1(){
-
//if the string is emmpty do nothing
-
if (mystring=='' || mystring==' '){/*alert ('mystring is empty');*/}
-
else {
-
//get the first space
-
getspace=mystring.indexOf(' ')+1;
-
//if there is no space left , we assume it is the last word
-
if (getspace==0){
-
//get the remaining string length
-
xxx=mystring.length;
-
//read the string from first char to its last
-
firstword=mystring.substring(0,xxx);
-
//read from position xxx to it remaining length *** seems useless but its needed
-
newstring=mystring.substring(xxx,mystring.length);
-
//write the firstword to span
-
InfoSpan.innerHTML+=' '+firstword;
-
//make sure mystring is empty
-
mystring='';
-
}else{
-
//if there is a space left ,read the string from the first char to the first space
-
firstword=mystring.substring(0,getspace);
-
//then write it to span
-
InfoSpan.innerHTML+=' '+firstword+Seperator;
-
//read the string from the first space to the end and assign it to newstring
-
newstring=mystring.substring(getspace,mystring.length);
-
}
-
//set the remaining string as mystring
-
mystring=newstring;
-
//call function test2
-
test1();
-
}
-
}
-
-
</script>
-
</head>
-
<body>
-
<span id="InfoSpan" ></span><br><br>
-
-
<a onclick="test1()" style="cursor:pointer;text-decoration:underline;">try me</a>
-
</body>
-
</html>
-
peace
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Radhika Sambamurti |
last post by:
Hi,
I've written a substring function.
The prototype is: int substr(char s1, char s2)
Returns 1 if s2 is a substring of s1, else it returns 0.
I have written this program, but Im sure there is an...
|
by: Darren Anderson |
last post by:
I have a function that I've tried using in an if then statement and I've
found that no matter how much reworking I do with the code, the expected
result is incorrect.
the code:
If Not...
|
by: btober |
last post by:
I can't seem to get right the regular expression for parsing data like
these four sample rows (names and addresses changed to ficticious values)
from a text-type column:
Yolanda Harris, 38, of...
|
by: Jean-François Michaud |
last post by:
Hello,
I've been looking at this for a bit now and I don't see what's wrong
with the code. Can anybody see a problem with this?
Here is an XSLT snippet I use.
<xsl:template match="graphic">...
|
by: dyc |
last post by:
how do i make use of substring method in order to extract the specified data from a a long string?
I also need to do some checking b4 extracting the data, for instance:
it only will extract the...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |