Results 1 to 3 of 3

Thread: Easier way to insert variables in text? *Solved*

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Easier way to insert variables in text? *Solved*

    Hello!
    Is there a shorter way I can do this?

    FullText = "Text 1 is " & Text1 & " and text 2 is " & Text2 & "."

    I was wondering if there was a method like this below, instead of splitting your text each time you need to insert a variable, is there a quicker method?

    vb Code:
    1. Private Sub CreateString()
    2.  
    3.         Dim Text1 As String = TextBox1.Text
    4.         Dim Text2 As String = TextBox2.Text
    5.  
    6.         Dim FullText As String
    7.         FullText = "Text 1 is [0] and text 2 is [1]."
    8.         '[0] = Text1 and [1] = Text2
    9.  
    10.         FullText = "Text 1 is " & Text1 & " and text 2 is " & Text2 & "."
    11.         'Long version
    12.  
    13.         Label1.Text = FullText
    14.  
    15.     End Sub

    Thanks, as always.
    Last edited by NinjaNic; May 15th, 2015 at 10:34 PM.

  2. #2

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Easier way to insert variables in text?

    Never mind! I found out that it is:

    FullText = String.Format("Text 1 is {0} and text 2 is {1}.", Text1, Text2)

    I hadn't seen your post yet. But thank you Edgemeal!

  3. #3
    New Member joyce chesley's Avatar
    Join Date
    May 2015
    Location
    smartmixers.com
    Posts
    5

    Re: Easier way to insert variables in text?

    Quote Originally Posted by NinjaNic View Post
    Never mind! I found out that it is:

    FullText = String.Format("Text 1 is {0} and text 2 is {1}.", Text1, Text2)

    I hadn't seen your post yet. But thank you Edgemeal!
    Are you a new coder. You can use String.Format and in addition for you use: StringBuilder

Tags for this Thread

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