I am trying to insert spaces in string
for example:
string = "hellohowarejames"
i woud like to insert a space for every 4 letters
so it will look like
"hell ohow arej ames"
I am trying to insert spaces in string
for example:
string = "hellohowarejames"
i woud like to insert a space for every 4 letters
so it will look like
"hell ohow arej ames"
Something like this untested, bug filled code?
Code:string AddSpaces(string Input) { int length = Input.size(); string output = string.empty; //for each block of 4 characters for(int i =0 ; i< length; i=i+4) { //copy 4 characters and a space to the output output += Input.substr(i, 4) + " "; } return output; }
Last edited by novacain; 12-11-2012 at 12:17 AM.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
You are lucky I did not writeI am coding everyday in PL/SQL, C#, VB.NET and ASP.NET at the moment, with some JavaScript thrown in to be annoying.Code:output := '';
I keep mixing syntax up and adding 'THEN' after loops/IFs.
Worse is when I code in PL/SQLCode:IF (someVar <> NULL) THEN
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill