Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to remove the spaces from a string
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
hi
try with this syntax
sVal = Replace("Sathiya Arunachalam"," ","") ' A binary comparison starting at the beginning of the string. Returns "SathiyaArunachalam"
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
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.
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
Thanks Suresh the replace function works fine. It removes all the spaces.
Reply
#5
Solved: 11 Years, 4 Months, 3 Weeks ago
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
Reply
#6
Solved: 11 Years, 4 Months, 3 Weeks ago
Why would we need to re-invent the wheel when Vbscript has provided a ready-made solution for your needs ? ;-)
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#7
Solved: 11 Years, 4 Months, 3 Weeks ago
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

Reply
#8
Solved: 11 Years, 4 Months, 3 Weeks ago
Dim str
str=" Quick test professional"
x=Split(str," ")

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

MsgBox y

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to remove text in the webedit silpavinod 3 13,880 07-12-2018, 11:08 AM
Last Post: vijaychourasiya0109@gmail.com
  how to remove null values in array venkatesh9032 0 2,910 02-19-2014, 06:51 PM
Last Post: venkatesh9032
  Replace a string in a word document with another string rekha.naik 8 15,582 11-14-2013, 12:58 PM
Last Post: pranikgarg
  how to remove values from an Array. ACCBAJPA 5 5,209 08-23-2013, 12:18 PM
Last Post: ssvali
  How to remove space between webelements silpavinod 2 3,327 10-11-2012, 02:53 PM
Last Post: silpavinod

Forum Jump:


Users browsing this thread: 1 Guest(s)