kasowitz
asked on
Change Text Arrangement? LEN?
Hi,
I knew how to do this at one time, but it now escapes me in VB.NET.
I have a text string "20060312" , when I stick this string into a textbox I want to rearrange the same text to look like "03122006" .
Any suggestion/help as to what is the quickest and most proper way to do this ? Does it involve using LEN statements? Thanks for all your help !
I knew how to do this at one time, but it now escapes me in VB.NET.
I have a text string "20060312" , when I stick this string into a textbox I want to rearrange the same text to look like "03122006" .
Any suggestion/help as to what is the quickest and most proper way to do this ? Does it involve using LEN statements? Thanks for all your help !
ASKER
Thanks for your reply bruintje,
I am having trouble using your example code..I get the following error:
startIndex cannot be larger than length of string.
Parameter name: startIndex
Any idea what Im doing wrong ?
I am having trouble using your example code..I get the following error:
startIndex cannot be larger than length of string.
Parameter name: startIndex
Any idea what Im doing wrong ?
if it were a date datatype you could use the format function:
Format(date, "mmddyyyy")
Format(date, "mmddyyyy")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
substring is zero-based. change it to mystring.substring(4,4) & mystring.substring(0,4)
You can regex the string too...
Dim DateRegEx As System.Text.RegularExpress ions.Regex = _
New System.Text.RegularExpress ions.Regex ("^(?<Year >([0-9]{4} ))(?<Day>( [0-9]{2})) (?<Month>( [0-9]{2})) $")
With DateRegEx.Match(TextBox1.T ext)
TextBox1.Text = .Groups("Day").Value & .Groups("Month").Value & .Groups("Year").Value
End With
Might be a bit overkill though
Dim DateRegEx As System.Text.RegularExpress
New System.Text.RegularExpress
With DateRegEx.Match(TextBox1.T
TextBox1.Text = .Groups("Day").Value & .Groups("Month").Value & .Groups("Year").Value
End With
Might be a bit overkill though
i admit cooking and answering questions here shouldn't go together :)
ASKER
Hmm, still not working for me. Same error.
I am actually grabbing my string from a SQL Data reader, and unfortunately the field type is text and not date. Here is my code...any ideas ?
Admit = myReader2("Field9").ToStri ng.Substri ng(4, 4) & myReader2("Field9").ToStri ng.Substri ng(0, 4)
textbox1.text = admit
I get the error:
startIndex cannot be larger than length of string.
Parameter name: startIndex
I am actually grabbing my string from a SQL Data reader, and unfortunately the field type is text and not date. Here is my code...any ideas ?
Admit = myReader2("Field9").ToStri
textbox1.text = admit
I get the error:
startIndex cannot be larger than length of string.
Parameter name: startIndex
ASKER
Sorry guys !...that worked perfect ! The current record I was on had that field as blank. Doh ! Thanks!
Hi ZeonFlash;
If you wanted to use Regex I think this is a better Regex solution.
mystring = System.Text.RegularExpress ions.Regex .Replace(m ystring, _
"^\s*?(\d{4})(\d\d)(\d\d)\ s*?$", "$2$3$1")
Fernando
If you wanted to use Regex I think this is a better Regex solution.
mystring = System.Text.RegularExpress
"^\s*?(\d{4})(\d\d)(\d\d)\
Fernando
Hi kasowitz;
Can you please post a comment in the https://www.experts-exchange.com/Community_Support/ and have the question reopened and then award the points to bruintje who had the solution you used. you will have to reference this question, https://www.experts-exchange.com/questions/21833535/Change-Text-Arrangement-LEN.html.
Thank you;
Fernando
Can you please post a comment in the https://www.experts-exchange.com/Community_Support/ and have the question reopened and then award the points to bruintje who had the solution you used. you will have to reference this question, https://www.experts-exchange.com/questions/21833535/Change-Text-Arrangement-LEN.html.
Thank you;
Fernando
if your string is always 8 characters as in your coment you could use
mystring.substring(5,4) & mystring.substring(1,4)
hope this helps a bit
bruintje