Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. String Arrays

String Arrays

Scheduled Pinned Locked Moved Visual Basic
questiondata-structures
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    beowulfagate
    wrote on last edited by
    #1

    How do I return an array of strings from a function? Just like the way String.Split does?

    M D 2 Replies Last reply
    0
    • B beowulfagate

      How do I return an array of strings from a function? Just like the way String.Split does?

      M Offline
      M Offline
      MohammadAmiry
      wrote on last edited by
      #2

      Try returning the array as Variant (in VB6) or Object (in VB.NET)

      B 1 Reply Last reply
      0
      • M MohammadAmiry

        Try returning the array as Variant (in VB6) or Object (in VB.NET)

        B Offline
        B Offline
        beowulfagate
        wrote on last edited by
        #3

        I can't do that. My development environment is such that Option Strict is On. I have to explicitly convert my array to a array of strings. Any other way?

        1 Reply Last reply
        0
        • B beowulfagate

          How do I return an array of strings from a function? Just like the way String.Split does?

          D Offline
          D Offline
          Dennis C Dietrich
          wrote on last edited by
          #4

          Hi Beowulf! How do I return an array of strings from a function? Just like the way String.Split does? Take a close look at the VB.NET declaration of Split[^]. It's got brackets after its type. All you have to do in the function is to create an array of the appropriate type and size and finally use a reference to it as the function's return value. For example:

          Option Explicit On
          Option Strict On

          Public Class Form1
          Private Sub Button1_Click(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles Button1.Click
          For Each str As String In TestFunction()
          MessageBox.Show(str)
          Next
          End Sub

          Private Function TestFunction() As String()
              Dim ReturnArray(1) As String
              ReturnArray(0) = "TestString"
              ReturnArray(1) = "Another String"
              TestFunction = ReturnArray
          End Function
          

          End Class

          Best regards Dennis

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups