Replacing multiple spaces

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Replacing multiple spaces

  • Creator
    Topic
  • #51445
    David Harrison
    Participant

    I’m looking for the best way to replace each occurrence of multiple spaces in a string with a single space.

    from

  • ”  This is        my  string       “

  • to

  • “This is my string”

  • Many thanks and Happy Christmas,

    Dave

Viewing 1 reply thread
  • Author
    Replies
    • #70337
      Keith McLeod
      Participant

      How about something like:

      set yourstring ”  This is        my  string       “

      regsub -all {s+} $yourstring { } newstring

      set finalstring [string trim $newstring]

      echo $finalstring

      I am sure there is a better way, but this should work for you….

    • #70338
      David Harrison
      Participant

      That does the business for me.

      Thanks,

      Dave

Viewing 1 reply thread
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forums

Forum Statistics

Registered Users
5,115
Forums
28
Topics
9,290
Replies
34,422
Topic Tags
286
Empty Topic Tags
10