2 Replies - 239 Views - Last Post: 21 January 2014 - 04:48 AM Rate Topic: ***-- 2 Votes

#1 TheLlamaOfGB  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-January 14

How to select a single digit in a 'Single' with a substring

Posted 20 January 2014 - 07:47 AM

I'm trying to select a single digit within a 10 digit code, such as 0 2 4 1 0 3 4 8 1 2, and trying to get just the 4...

I've used substrings to do this, but they only select all the numbers before it, ie. 0241034 is displayed.

0 2 4 1 0 3 4 8 1 2 is what I'm using to test this program. Here's what I'm using:

 Dim ISBNNum As String
ISBNNum = InputBox.Text
            ISBN1 = ISBNNum.Substring(0, 1)
            ISBN2 = ISBNNum.Substring(0, 2)
            ISBN3 = ISBNNum.Substring(0, 3)
            ISBN4 = ISBNNum.Substring(0, 4)
            ISBN5 = ISBNNum.Substring(0, 5)
            ISBN6 = ISBNNum.Substring(0, 6)
            ISBN7 = ISBNNum.Substring(0, 7) 


0, 7 because 4 is the seventh digit. To this the program replies "0241034" when I try to display ISBN7 in a message box.

Any help is much appreciated! :helpsmilie:

Edit: Digit in a 'String'

Is This A Good Question/Topic? 0
  • +

Replies To: How to select a single digit in a 'Single' with a substring

#2 ybadragon  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 151
  • View blog
  • Posts: 968
  • Joined: 11-May 12

Re: How to select a single digit in a 'Single' with a substring

Posted 20 January 2014 - 07:51 AM

have you read up on Substring? The reason it is returning the entire thing is because you are telling it to take the character at index 0 with a length of 7 characters which is 0241034 What you want is to get the character at index 7 with a length of 1
Was This Post Helpful? 2
  • +
  • -

#3 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 102
  • View blog
  • Posts: 584
  • Joined: 01-October 08

Re: How to select a single digit in a 'Single' with a substring

Posted 21 January 2014 - 04:48 AM

Strings are an Array of characters, so you can access them in the following way:

        Dim s As String = "01234"
        Dim n1 As String = s(0)
        Dim n2 As String = s(1)
        Dim n3 As String = s(2)
        Dim n4 As String = s(3)
        Dim n5 As String = s(4)


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1