.net - Substring - argument out of range exception - startIndex parameter -


assume have following string in textbox1: fpo100200%10&ford*

now, have 2 more textboxes gets data substrings of textbox1. have following code:

public class form1 private function textmoves(mytext string, indexchar string)     dim index integer = mytext.indexof(indexchar)     return index end function private sub splittext()     dim text string = textbox1.text     textbox2.text = text.substring(0, textmoves(text, "%"))     textbox3.text = text.substring(textmoves(text, "%"), textmoves(text, "&")) end sub  private sub button1_click(sender object, e eventargs) handles button1.click     splittext() end sub 

end class

im trying in texbox2 substring fpo100200, in texbox3 substring 10.

as added line textbox3, threw me argument out of range error. can tell me im doing wrong? alot!

le: also, how can make textboxes populate data when text changed in textbox1, automatically, without pressing button?

second parameter length, not end position. reason first expression worked position initial index zero.

to "10" use

textbox3.text = text.substring(textmoves(text, "%")+1, textmoves(text, "&")-textmoves(text, "%")-1) 

or better

dim pos integer = textmoves(text, "%") textbox2.text = text.substring(0, pos) textbox3.text = text.substring(pos+1, textmoves(text, "&")-pos-1) 

demo.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -