Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Removing Space(s) within a string

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    49

    Resolved [RESOLVED] [2005] Removing Space(s) within a string

    Hi everyone!

    I just wanna ask on how to remove space(s) within a string. For example, I have a string "Hello world" and my output should be "Helloworld".

    I've already used the Trim Function but it won't give me the desired output.

    Thanks a lot!

    Radic
    Last edited by radic; Mar 26th, 2007 at 11:53 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Removing Space(s) within a string

    Use the Replace method. Also, please provide descriptive titles for your threads.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Removing Space(s) within a string

    vb Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.         Dim s As String = "Hello World"
    3.         MessageBox.Show(s.Replace(" ", ""))
    4.     End Sub

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    49

    Re: [RESOLVED] [2005] Removing Space(s) within a string

    Thanks so much dude! =)

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Removing Space(s) within a string

    This is a small thing and not specifically related to the question but you should not use literal empty strings. It is "more correct" to use the String.Empty property:
    vb Code:
    1. MessageBox.Show(s.Replace(" ", String.Empty))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    49

    Re: [RESOLVED] [2005] Removing Space(s) within a string

    Thanks for the insight!

  7. #7
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Talking Re: [RESOLVED] [2005] Removing Space(s) within a string

    Quote Originally Posted by jmcilhinney
    This is a small thing and not specifically related to the question but you should not use literal empty strings. It is "more correct" to use the String.Empty property:
    vb Code:
    1. MessageBox.Show(s.Replace(" ", String.Empty))
    Again Forget
    Thanks for That

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width