Jump to content

JavaScript Split String Help

- - - - -

  • Please log in to reply
2 replies to this topic

#1
stevie754

stevie754

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
I need help with a split statement in my JavaScript code, currently I am inputting
VARIABLENAME_WHERE_CLAUSE=1=1
and I am using the split statement
Wline = content.split("=");	

What I am looking the output to be is
Wline[0] = VARIABLENAME_WHERE_CLAUSE

Wline[1] = 1=1

but the code is spliting again at the second '=' any way to stop this and get the output I need.

NB Wline is the array the ini file is being read into. It works perfectly reading into the to array position WLine[0] and Wline[1] if there isn't a second =.

Edited by stevie754, 17 March 2011 - 02:18 AM.
Title was stupid


#2
stevie754

stevie754

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
sorry double post

EDIT: Just got it working, will test it a bit more but this is what i have if anyone else has the same problem.

while( !f.AtEndOfStream ){   

		content = f.ReadLine();

		//Wline = content.split("="); //this method works	if only 1 equals


		var s = content.indexOf('=');

		RParam[n] = [content.substring(0,s)];

		replace[n] = [content.substring(s+1)];	


		n++;

	}


#3
xx3004

xx3004

    Newbie

  • Members
  • PipPip
  • 13 posts
It's because split working with string only, and what you enter is not a string. In order to make it a string, wrap it by "" or '':

VARIABLENAME_WHERE_CLAUSE="1=1";


Reply if you still have a problem.
[x]




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users