Replace First N Occurrences in the String

前端 未结 6 1729
终归单人心
终归单人心 2021-01-14 06:45

How can I replace first N occurrences of many whitespaces and tabs in the following string:

07/12/2017  11:01 AM             21523 filename with         


        
6条回答
  •  时光取名叫无心
    2021-01-14 07:05

    I'd go with something like this. Though I kinda like Derek's answer so I'll look his up and understand what he/she does in it.

    var mytext = "some text separated by spaces and spaces and more spaces";
    var iterationCount = 4;
    while(iterationCount > 0)
      {
        mytext = mytext.replace(" ", "");
        iterationCount--;
      }
    return mytext;
    

提交回复
热议问题