I'm just wondering, I'm trying to make a very simple text processing or reduction. I want to replace all spaces (without these in " ") by one. I also have some semantic action dependent on each character read, so I that's why I don't want to use any regex. It's some kind of pseudo FSM model.
So here's the the deal:
s = '''that's my string, " keep these spaces " but reduce these '''
Desired ouput:
that's my string, " keep these spaces " but reduce these
What I would like to do is something like this: (I don't mention the '"' case to keep the example simple)
out = ""
for i in range(len(s)):
if s[i].isspace():
out += ' '
while s[i].isspace():
i += 1
else:
out += s[i]
I don't quite understand how the scopes are created or shared in this case.
Thank you for advice.
sstring, I'm blind I guess.