Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split method

Status
Not open for further replies.

dcarbone

Programmer
Aug 22, 2003
29
CA
Is it possible to split up a string based on spaces
ie. x = split(y," ")
 
Yes in javascript.
Code:
var wordArray = "This is my sentence".split(" ");

-pete
 
Yes. Actually you don't need to add " " the delimiter for spaces. It's the default.
 
Yes, however actually putting it in there makes better, self documented, code... even if it is just script! [wink]

-pete
 
ok...it doensnt seem to work in asp. if i use the javascript, then the variable cant be accessed by my asp code
 
Yeah I know...I always put it in there anyway (can't help it). ;-)
 
vbScript:
Code:
myVariable="These are some words"
myArray=split(myVariable," ")
for i = 0 to ubound(myArray)
   response.write myArray(i) & &quot;<br>&quot;
Next
 
Yeah, they hide that information in the documentation
Code:
<script language=&quot;javascript&quot; runat=&quot;server&quot;>
// server side javascript goes in here
</script>

or at the top of the page
<%@ language=&quot;javascript&quot; %>
then
<%
// javascript goes here
%>

Or if you are using VBScript there is probably a parallel technique I just don’t know it, and don’t want to [lol]

-pete
 
ok, the code that i'm trying to split comes from a textarea input box from a form...for some reason, the code will not split it up...maybe i should split based on a different character? carrage return?

 
Yeah… you certainly need to know what characters are in the string you are trying to parse to be successful at authoring code to parse it. Good point… I agree [wink]



-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top