-
May 15th, 2015, 10:24 PM
#1
Thread Starter
Addicted Member
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:
Private Sub CreateString()
Dim Text1 As String = TextBox1.Text
Dim Text2 As String = TextBox2.Text
Dim FullText As String
FullText = "Text 1 is [0] and text 2 is [1]."
'[0] = Text1 and [1] = Text2
FullText = "Text 1 is " & Text1 & " and text 2 is " & Text2 & "."
'Long version
Label1.Text = FullText
End Sub
Thanks, as always.
Last edited by NinjaNic; May 15th, 2015 at 10:34 PM.
-
May 15th, 2015, 10:33 PM
#2
Thread Starter
Addicted Member
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!
-
May 15th, 2015, 11:01 PM
#3
New Member
Re: Easier way to insert variables in text?
Originally Posted by NinjaNic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|