2019-04-16, 05:49 PM
(2019-04-16, 03:08 PM)Y_Less Wrote: Oh, we're playing code golf now are we :)
PHP Code:RemoveDoubleSpace(string[], i = 0)
{
while ((i = strfind(string, " ?", _, i)) != -1)
strdel(string, i, i 1);
}
(2019-04-15, 10:39 PM)Y_Less Wrote: Another way you can do this is to loop through once, and shift all letters backwards. ?Every time you see a space you increase this shift offset:
PHP Code:DeSpace(string[])
{
new
// Read index.
i = -1,
// Write index.
j = -1,
// Current character.
ch,
// Did we already see a space?
bool:space;
do
{
if ((ch = string[]) != ' ')
{
// Not a space, just copy it.
string[] = ch;
// Mark us as having NOT just seen a space.
space = false;
}
else if (!space)
{
// First space. ?Any more just ignore them.
string[] = ch;
// Mark us as having just seen a space.
space = true;
}
}
while (ch);
}
Is this better? ?I don't know. ?It will depend on the length of the string and the number of double spaces.
?it should be the definitive, but there are other way to solve this problem
3D modeler on Blender - OOP and functional programming programmer