Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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 !
0
kasowitz
Asked:
kasowitz
  • 3
  • 3
  • 2
  • +2
1 Solution
 
bruintjeCommented:
Hi kasowitz,

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
0
 
kasowitzAuthor Commented:
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 ?

0
 
MageDribbleCommented:
if it were a date datatype you could use the format function:

Format(date, "mmddyyyy")
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Fernando SotoCommented:
Hi kasowitz;

Not looking for the points just a correction to bruintje code sample above.

        mystring = mystring.Substring(4, 4) & mystring.Substring(0, 4)

String index are zero base.

Fernando
0
 
MageDribbleCommented:
substring is zero-based.  change it to mystring.substring(4,4) & mystring.substring(0,4)
0
 
ZeonFlashCommented:
You can regex the string too...

        Dim DateRegEx As System.Text.RegularExpressions.Regex = _
            New System.Text.RegularExpressions.Regex("^(?<Year>([0-9]{4}))(?<Day>([0-9]{2}))(?<Month>([0-9]{2}))$")

        With DateRegEx.Match(TextBox1.Text)
            TextBox1.Text = .Groups("Day").Value & .Groups("Month").Value & .Groups("Year").Value
        End With

Might be a bit overkill though
0
 
bruintjeCommented:
i admit cooking and answering questions here shouldn't go together :)
0
 
kasowitzAuthor Commented:
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").ToString.Substring(4, 4) & myReader2("Field9").ToString.Substring(0, 4)

textbox1.text = admit


I get the error:
startIndex cannot be larger than length of string.
Parameter name: startIndex
0
 
kasowitzAuthor Commented:
Sorry guys !...that worked perfect ! The current record I was on had that field as blank. Doh ! Thanks!
0
 
Fernando SotoCommented:
Hi ZeonFlash;

If you wanted to use Regex I think this is a better Regex solution.

        mystring = System.Text.RegularExpressions.Regex.Replace(mystring, _
            "^\s*?(\d{4})(\d\d)(\d\d)\s*?$", "$2$3$1")

Fernando
0
 
Fernando SotoCommented:
Hi kasowitz;

Can you please post a comment in the http://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, http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21833535.html.

Thank you;

Fernando
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now