Results 1 to 7 of 7

Thread: how would i remove right most spaces from a string?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    132

    how would i remove right most spaces from a string?

    Okay, lets say I had a string variable that contained "Hello World! ", (or whatever the string contained)

    how would i remove the the right most spaces to make it say "Hello World"

    (im reading in items from a text file using substrings that has fixed positions with one line of the text containing several different items)

    or does it automatically eliminate the right most spaces???

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

    Re: how would i remove right most spaces from a string?

    A String object has a TrimLeft method that removes leading characters, a TrimRight method that removes trailing characters and a Trim method that does both. You can specify the character(s) to trim or not, in which case spaces are assumed.
    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

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    132

    Re: how would i remove right most spaces from a string?

    it doesn't automatically delete the space(s) i just tested

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    132

    Re: how would i remove right most spaces from a string?

    you sure do save me a lot of time...hahaha

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2011
    Posts
    132

    Re: how would i remove right most spaces from a string?

    also, another quick question i have for you if you know the answer...

    Lets say I have a string that contained "Monday"
    would it be possible to find out when the next Monday would occur?

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

    Re: how would i remove right most spaces from a string?

    Quote Originally Posted by StevenA View Post
    you sure do save me a lot of time...hahaha
    I take it that that means that you worked out that it doesn't remove spaces from the original String but, like all String manipulation functions, returns a new String containing the changes.
    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

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

    Re: how would i remove right most spaces from a string?

    Quote Originally Posted by StevenA View Post
    also, another quick question i have for you if you know the answer...

    Lets say I have a string that contained "Monday"
    would it be possible to find out when the next Monday would occur?
    That's nothing to do with the topic of this thread. Please keep each thread to a single topic and each topic to a single thread. If you want to address a new topic then please create a new thread, with a title that indicates that topic.
    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

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