Results 1 to 5 of 5

Thread: Newbie easy question

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    Newbie easy question

    I have the following:

    strAcctNumber = strAcctNumberWithBank.Substring(2, 9)

    What I really want is to grad the account number from position 3 on no matter what the lenght. As you can see now, I am restricted to 9 characters long, and I want it to be where is can be less than or greater than 9, but it must start @ position 3. What the correct syntaxt or best route to accomplish this.

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: Newbie easy question

    That would be
    Code:
    strAcctNumber = strAcctNumberWithBank.Substring(2, strAcctNumberWithBank.Length - 2)
    strAcctNumberWithBank.Length - 2 supplies you with the index of the last char of the string.
    VB 2005, Win Xp Pro sp2

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

    Re: Newbie easy question

    That would just be:
    Code:
    strAcctNumber = strAcctNumberWithBank.Substring(2)
    You only need the second parameter if you want to stop before the end of the string.
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    Re: Newbie easy question

    Appreciate the quick feedback, why is it when I have the following:

    strAcctNumberWithBank = Trim(result(0))
    strAcctNumber = strAcctNumberWithBank.Substring(2)

    I debug and I am not getting an stracctnumber

    strAcctNumber Nothing String
    strAcctNumberWithBank "98110900016" String

    I am expecting strAcctNumber to show '110900016' String

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    2

    Re: Newbie easy question

    Nevermind, I think it might be because I was only debugging that one line. Sorry, new to all this.

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