Jump to content

Replace any amount of space

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Frantic

Frantic

    Learning Programmer

  • Members
  • PipPipPip
  • 91 posts
If I have a file like this:

I have a file that has space

How can I do a replace of any amount of space (1 to 20)? I'd like to take that line and replace it with something like : so I can then split into an array.

#2
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts

Frantic said:

If I have a file like this:

I have a file that has space

How can I do a replace of any amount of space (1 to 20)? I'd like to take that line and replace it with something like : so I can then split into an array.

You'll want to do a RegEx lreplace. The pattern would be " +" (1 or more space) and you'd replace with the single character you want (either a single space or colon - whatever you prefer).

#3
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
That is a bit odd, your sentance only has one space between each word.

#4
hoser2001

hoser2001

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
Usually sentences do only have one space between each word...

#5
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
HTML compresses spaces. Do a View Source to see his actual comment with spaces intact.