vb.net - using toupper and tolower in visual basic -
trying change case of first letter of parsed strings segments. if user enters "john wayne doe" in txtname display "john wayne doe" entered way shows in book message box displays parsed string entered in above example return "john wayne doe" figure logic error since known lot have no idea made error.
dim name string = txtname.text name = name.trim dim names() string = name.split(cchar(" ")) dim firstname string = names(0) dim middlename string = names(1) dim lastname string = names(2) dim firstletters1 string = firstname.substring(0, 1).toupper dim otherletters1 string = firstname.substring(1).tolower dim firstletters2 string = middlename.substring(0, 1).toupper dim otherletters2 string = middlename.substring(1).tolower dim firstletters3 string = lastname.substring(0, 1).toupper dim otherletters3 string = lastname.substring(1).tolower messagebox.show("first name: " & firstname & vbcrlf & "middle name: " & middlename & vbcrlf & "last name: " & lastname)
try this:
messagebox.show(_ "first name: " & firstletters1 & otherletters1 & vbcrlf & _ "middle name: " & firstletters2 & otherletters2 & vbcrlf & _ "last name: " & firstletters3 & otherletters3)
string immutable class, toupper
, tolower
calls create new instances. in message box passing old unprocessed instances.
update alternatively, can use our old call:
messagebox.show("first name: " & firstname & vbcrlf & "middle name: " & middlename & vbcrlf & "last name: " & lastname)
as long before:
firstname = firstletters1 & otherletters1 middlename = firstletters2 & otherletters2 lastname = firstletters3 & otherletters3
this might better idea on how string's immutability works.
Comments
Post a Comment