954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to get rid of spaces

hello can you help me please,

how can i remove lots of spaces in a string for example:

The space space space space quick space space space brown fox.

the output should like this.

Thequickbrownfox


can you help on this...thank you in advance and I'm hoping for your positive response...

jemz
Master Poster
763 posts since Jan 2010
Reputation Points: 9
Solved Threads: 0
 

You need to use the function Replace.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 
You need to use the function Replace.


hello sir thank you for the reply,but how can i make without using the replace sir?
thank you in advance hoping for your positive responds...

jemz
Master Poster
763 posts since Jan 2010
Reputation Points: 9
Solved Threads: 0
 

Hi Jemz. Have not heard from you in some time now.:)

Use the trim function -

Text1.Text = Trim(Text1.Text)


Debasisdas code will look something like -

Text1.Text = Replace(Text1.Text," ","")


, which by the way is the best way to remove empty spaces....:)

You can also add the below code to a module and use it throughout your application -

'To a module add ----
Public Function StripOut(From as string, What as string) as string

    Dim i as Integer

    StripOut = From
    for i = 1 to len(What)
        StripOut = Replace(StripOut, mid$(What, i, 1), "")
    next i

End Function

'In your form call it as in ----

Text1.Text = StripOut(" ", "")
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Hi Jemz. Have not heard from you in some time now.:)

Use the trim function -

Text1.Text = Trim(Text1.Text)

Debasisdas code will look something like -

Text1.Text = Replace(Text1.Text," ","")

, which by the way is the best way to remove empty spaces....:)

You can also add the below code to a module and use it throughout your application -

'To a module add ----
Public Function StripOut(From as string, What as string) as string

    Dim i as Integer

    StripOut = From
    for i = 1 to len(What)
        StripOut = Replace(StripOut, mid$(What, i, 1), "")
    next i

End Function

'In your form call it as in ----

Text1.Text = StripOut(" ", "")

Hello sir AndreRet,


Hi! thank you for the reply,sorry for being absent for many days or month because I a'm very busy for some activities And I really miss this daniweb forum and also to you all sir who always help me and teaches me...


About the replace sir i already make it but, is there another way to code sir without using the replace or the built in function Replace?...thank you in advance hoping for your positive responds...

jemz
Master Poster
763 posts since Jan 2010
Reputation Points: 9
Solved Threads: 0
 

You can use loops

dim i as integer
dim myString as string

for i = 1 to len(text1.text)
 if mid(text1.text,i,1) <> " " then
 myString = myString & mid(text1.text)
 endif
next i

you can do something like that. Thanks

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

Why can you not use the replace function Jemz? If you look at the one line of code using "Replace" compared to Jhai's 7 lines of code, it only makes sense to use the replace function for added speed in your application.

@Jhai, nice alternative offered.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

@Andre. Thanks.

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

It's a pleasure Jhai.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

I think i need to correct that code :)

Dim i as Integer
Dim myString as string

For i = 1 to Len(Text1.Text)
 If Mid(Text1.Text,i,1) <> " " then
 myString = myString & Mid(Text1.Text,i,1) '<-- Corrected this one...
 EndIf
Next i
jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

Jemz, has this sort your problem?

If so, you know what to do.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Hi Jemz. Have not heard from you in some time now.:)

Use the trim function -

Text1.Text = Trim(Text1.Text)

Debasisdas code will look something like -

Text1.Text = Replace(Text1.Text," ","")

, which by the way is the best way to remove empty spaces....:)

You can also add the below code to a module and use it throughout your application -

'To a module add ----
Public Function StripOut(From as string, What as string) as string

    Dim i as Integer

    StripOut = From
    for i = 1 to len(What)
        StripOut = Replace(StripOut, mid$(What, i, 1), "")
    next i

End Function

'In your form call it as in ----

Text1.Text = StripOut(" ", "")


hello thank you for the reply both of you sir jhai and AndreRet...okay i will try this one i will write again if i have doubt...

jemz
Master Poster
763 posts since Jan 2010
Reputation Points: 9
Solved Threads: 0
 

Jemz, has this sort your problem?

If so, you know what to do.:)

yes thank you sir for helping me...it works...

jemz
Master Poster
763 posts since Jan 2010
Reputation Points: 9
Solved Threads: 0
 

It was a pleasure.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You