Results 1 to 5 of 5

Thread: [RESOLVED] Removing Spaces

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Resolved [RESOLVED] Removing Spaces

    I am reading data in from a text file that has a lot of spacing between fields:
    name address phone.
    Each column is a fixed length, so if i use substring() i can gather the whole field. The problem is when I use trim() it doesnt remove all the spaces. In debug mode when I go over a variable I will see "name \0\0\0\0\0\0\0\0" "address\0\0\0\0\0" etc. Is there another form of trim() that I can use to remove those. Thanks

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

    Re: Removing Spaces

    Are those spaces or null characters? If you call Trim without an argument is will remove spaces only. If you want to remove other characters you have to specify those characters. I suggest that you read the MSDN help topic for the String.Trim method and it will explain.
    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
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: Removing Spaces

    I actually beleive they are null characters

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Removing Spaces

    If you're wanting to remove all of the null characters, Trim isn't for you. Trim only removes leading and trailing characters. Use replace:
    PHP Code:
    string blah "name \0\0\0\0\0\0\0\0" "address\0\0\0\0\0";
    blah blah.Replace("\0"""); 
    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Re: Removing Spaces

    that works, thanks

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