Micro Focus QTP (UFT) Forums
How to remove the spaces from a string - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to remove the spaces from a string (/Thread-How-to-remove-the-spaces-from-a-string)



How to remove the spaces from a string - Anand - 05-30-2011

Hi,

I have a string with spaces example

Full name="Anand Kumar Dave"
i want to remove the spaces and store in another variable as
"AnandKumarDave" how can we do this ??

There is list of names and i have to remove spaces from all the names.
some names are having only one space in between and some have two spaces.


RE: How to remove the spaces from a string - Sathiya - 05-30-2011

hi
try with this syntax
sVal = Replace("Sathiya Arunachalam"," ","") ' A binary comparison starting at the beginning of the string. Returns "SathiyaArunachalam"


RE: How to remove the spaces from a string - suresh vasu - 05-30-2011

Hi Anand,

I have written some code for you, which is working fine. It will work for any string irrespective of spaces it contains.

Code:
str = "Suresh Vasu Kondapally"
newStr = ""
For i=1 to len(str)
    char = Mid(str,i,1)
    if(char<>" ") then
    newStr = newStr+Mid(str,i,1)
    End if
Next
MsgBox newStr

Do let me know if you get problem in using the code.

Suresh.


RE: How to remove the spaces from a string - Anand - 05-30-2011

Thanks Suresh the replace function works fine. It removes all the spaces.


RE: How to remove the spaces from a string - nandish - 07-15-2013

Code:
str = "Suresh Vasu Kondapally"
x=split(str," ",-1,1)
y=ubound(x)
For i=0 to y
msgbox x(i)
    str1=str1+x(i)
Next
msgbox str1



RE: How to remove the spaces from a string - basanth27 - 07-15-2013

Why would we need to re-invent the wheel when Vbscript has provided a ready-made solution for your needs ? ;-)


RE: How to remove the spaces from a string - venkatesh9032 - 02-19-2014

Hi anand,,
You can use Trim function..

Dim str
Str=" Quick test professional"

Msgbox Str------->First run this and comment

Temp=Trim(Str)
Msgbox Temp------>Second run this


You will get it




RE: How to remove the spaces from a string - sreekanthP - 08-12-2019

Dim str
str=" Quick test professional"
x=Split(str," ")

For i=1 To UBound(x) Step 1
    y = y&x(i)
Next

MsgBox y