Reputation: 71
I am currently working on a really basic scripting langauge (called EngineScript) that gets the first 4 letters of a textbox's content (in a Windows Form project) and compares it to a in-program list of keywords and then uses the remaining characters to form an argument to the keywords... I was wondering weather you had some code ideas on how to go about placing the first 4 letters in one variable and then the remaining characters into another. My langauge will be single command.. i.e you will only be able to run one command per program.
Upvotes: 4
Views: 43088
Reputation: 826
Carefull with Substring() function as it assumes that the textbox length is greater or equal than the second parameter. So if in your input someone puts less than 4 characters it will blow.
You should this to be safe:
Dim txt1 as String = Textbox1.Text
Dim first4Chars = If(txt1.Length > 4, txt1.Substring(0, 4), txt1.SubString(0,text.Length))
Upvotes: 1
Reputation: 5719
Your question is not too clear ..
But you can try this
dim sVar as string = mid(TextBox1.text,1,4)
Upvotes: 0
Reputation: 688
I will show you a good hint on how to get the first four letters, and see what you can put together with that. VB was a pain in my neck!! I struggled through it, and realized that is the only way to learn.. =)
dim substring as string
substringA = Left$("Entered String", 4)
strSubstrA = "Ente"
substringB = Left$("What about a space?", 6)
strSubstrB = "What a"
Upvotes: 1
Reputation: 30418
String.Substring() should work:
Dim first4Chars = TextBox1.Text.Substring(0, 4)
Dim restOfChars = TextBox1.Text.Substring(4)
Upvotes: 9
Reputation: 56745
something like this:
Dim l4 as string, rest as string
l4 = LEFT(TextBox1.Text, 4)
rest = MID(TextBox1.Text, 5, LEN(TextBox1.Text))
Upvotes: 0