How to remove multiple spaces in between a string

5,268 views
Skip to first unread message

Sreya Dingari

unread,
May 8, 2015, 12:23:31 PM5/8/15
to robotframe...@googlegroups.com
Hi, I am a beginner to Robot framework and need some help removing multiple spaces in between a string.

for example:
I have a string like this..

'WATERLOO ON'

I want this to be converted to:
'WATERLOO ON'


In general, I need something to convert multiple spaces to single space, when i do not know how many spaces the string has.


Thank you

Tatu Aalto

unread,
May 8, 2015, 1:09:36 PM5/8/15
to dsr...@gmail.com, robotframework-users

Ugh

Using String library Replace String Using Regexp keyword[1] should do the trick for you.

-Tatu
Send from my mobile
[1] http://robotframework.googlecode.com/svn/trunk/doc/libraries/String.html#Replace String Using Regexp

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Nadim

unread,
Sep 19, 2018, 5:08:54 AM9/19/18
to robotframework-users
We can do it in two ways as i know.
Method 1:  Using String Library

${Text}=   Replace String   " WAT   ERL O  O         ON "    ${space}   ${empty}

Method 1:  Using BuiltIn Library

${Text}=   Evaluate   " WAT   ERL O  O         ON ".replace(" ", "")


Hope this helps!!

Mark Walters

unread,
Dec 23, 2019, 6:39:27 AM12/23/19
to robotframework-users
It seems Tatu's link is no longer valid, so in case others come here looking for the solution, I believe this is what he was sharing:

${test3}    Replace String Using Regexp    ${test}    ${SPACE}+    ${SPACE}

So where ${test} contains       "one@ @space, two@  @spaces Six@      @spaces, Five@     @spaces"       (length = 63)
     ${test3} will contain "one@ @space, two@ @spaces Six@ @spaces, Five@ @spaces"                 (length = 53, i.e. the 10 superfluous spaces have been removed)

 Mark

Rahul Bhatia

unread,
Apr 23, 2020, 5:13:39 AM4/23/20
to robotframework-users
I have data in a variable which I read from a CSV file:
@{data}= M, M  Ma, U S S, 4/22/2020 2:43:25 AM, , , , , 

there are 2 spaces in M and Ma, I want one space there, also there is a space after every comma, I also want to remove that.

please suggest.
Reply all
Reply to author
Forward
0 new messages