Newbie wants to split up strings 
Author Message
 Newbie wants to split up strings

Hi there

I'm looking for function that splits up a string into two i.e.:

Function called with

Fullname = "Alex_Shirley"

Function returns:

Firstname = "Alex"
Lastname = "Shirley"

Another example:

Fullname = "Fred_Flintstone"
returns
Firstname = "Fred"
Lastname = "Flintstone"

(The Fullname value will always have an underscore between the firstname and
lastname).

What's the best way to go about this? Do I use the replace function. I've
looked through MSDN help and can't see anything that helps.

Many thanks

Alex Shirley



Tue, 22 Jul 2003 19:31:12 GMT  
 Newbie wants to split up strings
Hello,

Try to use the split function from the String object.
And return an Array from your function.

function yourFunction(fullName){

  fullName = new String(fullName);
  var namesArray = fullName.split("_");
  return namesArray; // namesArray[0] = firstName, namesArray[1] = lastName

Quote:
}
-----Original Message-----

Hi there

I'm looking for function that splits up a string into two i.e.:

Function called with

Fullname = "Alex_Shirley"

Function returns:

Firstname = "Alex"
Lastname = "Shirley"

Another example:

Fullname = "Fred_Flintstone"
returns
Firstname = "Fred"
Lastname = "Flintstone"

(The Fullname value will always have an underscore between the firstname and
lastname).

What's the best way to go about this? Do I use the replace function. I've
looked through MSDN help and can't see anything that helps.

Many thanks

Alex Shirley

.



Tue, 22 Jul 2003 19:59:37 GMT  
 Newbie wants to split up strings
split method:

  Fullname = "Fred_Flintstone"
  Names = Fullname.split("_")

returns
Names[0] = "Fred"
Names[1] = "Flintstone"

JScript Documentation
http://msdn.microsoft.com/scripting/jscript/download/jsdoc.exe
http://msdn.microsoft.com/scripting/jscript/techinfo/jsdocs.htm

=-=-=
Steve
-=-=-


Quote:
> Hi there

> I'm looking for function that splits up a string into two i.e.:

> Function called with

> Fullname = "Alex_Shirley"

> Function returns:

> Firstname = "Alex"
> Lastname = "Shirley"

> Another example:

> Fullname = "Fred_Flintstone"
> returns
> Firstname = "Fred"
> Lastname = "Flintstone"

> (The Fullname value will always have an underscore between the firstname
and
> lastname).

> What's the best way to go about this? Do I use the replace function. I've
> looked through MSDN help and can't see anything that helps.

> Many thanks

> Alex Shirley



Tue, 22 Jul 2003 21:09:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how to split a split string

2. wanted->split ps-files ->2 batches ->pr double-sided

3. Split string by regular expression (ie. date)

4. Splitting Strings

5. String Split

6. Splitting a string into each character..

7. SPLIT A LONG STRING TO PUT IN A MULTILINE BOX

8. SPLIT A LONG STRING

9. Result of .split on a null string

10. Splitting a string into an array

11. Split string by regular expression (ie. date)

12. Splitting a String

 

 
Powered by phpBB® Forum Software