arnololo123
asked on
Update a string seperated by | using split
Hi,
I have a string, let's say: var mystring= '6|8|444|2|9|4|2|1|6|77|99 8|111'
I would like to change in JAvscript for example the value 444 in the string by another value assuming that I know that 444 is at position 3
Thanks
I have a string, let's say: var mystring= '6|8|444|2|9|4|2|1|6|77|99
I would like to change in JAvscript for example the value 444 in the string by another value assuming that I know that 444 is at position 3
Thanks
ASKER
Hello,
I can't make it work, please see below my function:
I can't make it work, please see below my function:
function CostPOPUP()
{
var mySplitResult=document.all('<%=HF_LTA.ClientID%>').value.split('|');
for(i = 0; i < mySplitResult.length; i++)
{
if(i==parseInt(document.all('<%=inhRow.ClientID%>').value))
{mySplitResult[i]=document.all('<%= Tbx_LTATargetnew.ClientID%>').value +'$'+document.all('<%= Tbx_LTAScopenew.ClientID%>').value;}
}
document.all('<%=HF_LTA.ClientID%>').value=mySplitResult.join();
alert( document.all('<%=HF_LTA.ClientID%>').value.split('|')[document.all('<%=inhRow.ClientID%>').value].split('$')[0]);
}
This changes the 444 to 555. Also puts the pipe characters back after the array join.
var strValues ='6|8|444|2|9|4|2|1|6|77|998|111';
var arrValues = strValues.split('|');
arrValues[2] = 555;
var strOut = arrValues.join();
strOut = strOut.replace(/,/g,"|");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great answer with an example
Open in new window