/    Sign up×
Community /Pin to ProfileBookmark

Maintaining spaces in a string — URGENT!!!

Hi All,

I’m having real dificulty with a script and need help asap.

I have split a text string up which might or might not have spaces in it. Basicaly i have a string like this “13071406 080709” any space will always be 2 characters long. Now I split this string up and display this in text boxes 2 digits to each box, if the user does not amend these digits the same string will be combined and written back. The thing is the characters when I put back together to the original ignores the space so the string looks like this when getting sent back “13071406080709”. What i need is for all characters to be returned to there same position and if the text box is blank or just 1 character long the text box value padded out with a space or spaces.

This is the code i use to split the text

[CODE]xx = dvxGetdavoxfield(‘QBIG1’)

dvxSetuserfield(‘home_buildings_day’,xx.substring(1,3)) ;
dvxSetuserfield(‘hom_buildings_month’,xx.substring(3,5)) ;
dvxSetuserfield(‘home_contents_day’,xx.substring(5,7)) ;
dvxSetuserfield(‘home_contents_month’,xx.substring(7,9)) ;
dvxSetuserfield(‘motor’,xx.substring(9,11)) ;
dvxSetuserfield(‘motormonth’,xx.substring(11,13)) ;
dvxSetuserfield(‘pet’,xx.substring(13,15)) ;
dvxSetuserfield(‘petmonth’,xx.substring(15,17)) ;
dvxSetuserfield(‘travel’,xx.substring(17,19)) ;
dvxSetuserfield(‘travelmonth’,xx.substring(19,21)) ;
;[/CODE]

This is the code i use to piece it back together

[CODE]dvxGetuserfield(‘home_buildings_day’)+
dvxGetuserfield(‘hom_buildings_month’)+
dvxGetuserfield(‘home_contents_day’)+
dvxGetuserfield(‘home_contents_month’)+
dvxGetuserfield(‘motor’)+
dvxGetuserfield(‘motormonth’)+
dvxGetuserfield(‘pet’)+
dvxGetuserfield(‘petmonth’)+
dvxGetuserfield(‘travel’)+
dvxGetuserfield(‘travelmonth’) [/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsJul 25.2005 — [CODE]

<html>
<head>
<script>
// Format String

var zxcFS,tb1,tb2,tb3,tb4;

function zxcMakeFormatString(zxc){
zxcFS='';
for (zxc0=0;zxc0<zxc.length;zxc0++){
if (zxc.charAt(zxc0)!=' '){ zxcFS+='~'; }
else { zxcFS+=' '; }
}
}



function zxcSplit(){
zxcS=document.getElementById('Source');
tb1=document.getElementById('TB1');
tb2=document.getElementById('TB2');
tb3=document.getElementById('TB3');
tb4=document.getElementById('TB4');

zxcMakeFormatString(zxcS.value);
tb1.value=zxcS.value.substring(0,3);
tb2.value=zxcS.value.substring(3,6);
tb3.value=zxcS.value.substring(6,9);
tb4.value=zxcS.value.substring(9,zxcS.value.length);
}

function zxcCombine(){
zxccom=tb1.value+tb2.value+tb3.value+tb4.value;
zxccom=zxccom.replace(/s/g,'');
zxcc=0
zxcout='';
for (zxc0=0;zxc0<zxcFS.length;zxc0++){
if (zxcFS.charAt(zxc0)=='~'){ zxcout+=zxccom.charAt(zxcc++); }
else { zxcout+=zxcFS.charAt(zxc0); }
}
document.getElementById('OutPut').value=zxcout;
}

</script>

</head>
<body>

Input <input id="Source" value="" size="15" >
<input type="button" value="Split" onclick="zxcSplit();" ><br>
<br>
<input id="TB1" size="10" ><br>
<input id="TB2" size="10" ><br>
<input id="TB3" size="10" ><br>
<input id="TB4" size="10" ><br>
<br>
<input type="button" value="Combine" onclick="zxcCombine();" ><br>
<br>
Output <input id="OutPut" value="" size="15" >


</body>
</html>


[/CODE]
×

Success!

Help @G-star spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...