...

View Full Version : Invisible Space in Text String



jason_kelly
12-13-2011, 04:12 PM
Hello,

I need your help.

I would like to insert a few blank spaces in a text string:

eg.

string = 123456(space)(space)(space)7891011

How do you do this?

Thanks a bunch

Jay

devnull69
12-13-2011, 04:22 PM
Your description is not easy to understand ... first of all I would say


myString = "123456 7891011";

But this might be too easy. On a second glimpse I would assume that you actually have a string already and you want to insert three spaces after the first 6 characters ... is that true?


var myString = "1234567891011";
myString = myString.substring(0,6) + " " + myString.substring(6);

On a third glimpse ... you were talking about invisible spaces ... what would make those spaces invisible?

Nevertheless, this is a generic function were you can give the insert positon and the number of spaces as parameters


function insertSpaces(theString, insertPosition, numberOfSpaces) {
var returnString = "";
for(i=0; i<numberOfSpaces; i++) returnString += " ";
return theString.substring(0, insertPosition-1) + returnString + theString.substring(insertPosition-1);
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum