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...

You need to use the function Replace.

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...

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(" ", "")

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...

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

commented: Nice alternative. +4

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.:)

It's a pleasure Jhai.:)

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

Jemz, has this sort your problem?

If so, you know what to do.:)

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, has this sort your problem?

If so, you know what to do.:)

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

It was a pleasure.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.