Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    182
    Thanks
    139
    Thanked 0 Times in 0 Posts

    Invisible Space in Text String

    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

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Your description is not easy to understand ... first of all I would say
    Code:
    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?
    Code:
    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
    Code:
    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);
    }
    Last edited by devnull69; 12-13-2011 at 03:25 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •