locked
How to use Left, Right, and Mid Strings in VB

    Question

  • I am building a Windows Store App in VB. I am having trouble getting the substring Left, Right, and Mid functions to work. I have found a couple of examples, but I can't get them to work. I understand that I have to declare shared functions, I think? Not sure where to do that. Maybe someone could post full examples for me including the declarations and sample usage. I am sure that others would benefit as well. 

    Thanks,

    David

    Saturday, June 7, 2014 2:56 AM

Answers

  • I figured it out. Here it is is for the benefit of others. This code gets the string representation of an Image URI and then extracts the file name from the string. The URI is to the last slash is 16 characters long. Everything after that is the file name. For example, 

    SourceImage1 = NewBitmapImage(NewUri("ms-appx:///Assets/Bird.png"))

    Here is the code that gets Bird.png...

                Dim left, right, mid As String
                Dim bm As BitmapImage
                Dim imageOrigin As Uri
                bm = sender.Source
                Dim strText As String
                If Not (bm Is Nothing) Then
    
                    'This may or may not be set
                    imageOrigin = bm.UriSource
                    strText = imageOrigin.OriginalString                
                    right = strText.Substring(16, strText.Length - 16)
                End If

    Sincerely,

    David

    • Marked as answer by David.Warwick Saturday, June 7, 2014 3:27 AM
    Saturday, June 7, 2014 3:26 AM

All replies

  • I figured it out. Here it is is for the benefit of others. This code gets the string representation of an Image URI and then extracts the file name from the string. The URI is to the last slash is 16 characters long. Everything after that is the file name. For example, 

    SourceImage1 = NewBitmapImage(NewUri("ms-appx:///Assets/Bird.png"))

    Here is the code that gets Bird.png...

                Dim left, right, mid As String
                Dim bm As BitmapImage
                Dim imageOrigin As Uri
                bm = sender.Source
                Dim strText As String
                If Not (bm Is Nothing) Then
    
                    'This may or may not be set
                    imageOrigin = bm.UriSource
                    strText = imageOrigin.OriginalString                
                    right = strText.Substring(16, strText.Length - 16)
                End If

    Sincerely,

    David

    • Marked as answer by David.Warwick Saturday, June 7, 2014 3:27 AM
    Saturday, June 7, 2014 3:26 AM
  • Saturday, June 7, 2014 3:59 AM
    Owner