Results 1 to 5 of 5

Thread: [RESOLVED] Strings and numbers

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Resolved [RESOLVED] Strings and numbers

    Hello everybody!

    I'm interested in: how to split for example this record:

    ab ab ab 22.04.2009

    So, I want to have two variables.

    A: ab ab ab

    B: 22.04.2009

    So, first string will always be a one word (or more), and the another string will always be number (always as date)

    Thanks!

  2. #2
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: Strings and numbers

    Well first I need to know what if any assumptions there are. Meaning, does the date portion of the string always exist in DD/MM/YYYY format? Does the date always occur at the end of the string? That way you know that the date portion of the string is always 10 characters long(including the periods). Using this info you can subtract that value from the length of the string and use that to determine where the text and date portion of the string begins. Here is an example...

    Code:
    Dim Record as String = "ab ab ab 22.04.2009"
    Dim WordPartOfRecord as String
    Dim DatePartOfRecord as DateTime
    
    WordPartOfRecord = Record.Substring(0, (Record.Length - 10))
    DatePartOfRecord = Convert.ToDateTime(Record.SubString(WordPartOfRecord.Length+1))

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    Re: Strings and numbers

    Thank you!

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [RESOLVED] Strings and numbers

    As long as all your dates having the same format dd.MM.yyyy then that code will work. If any of the dates is in short format, for example 22.4.2009 or 1.2.2010 instead of 22.04.2009 or 01.02.2010 then that code will not work.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5
    Hyperactive Member The Fire Snake's Avatar
    Join Date
    Sep 2009
    Location
    USA
    Posts
    401

    Re: [RESOLVED] Strings and numbers

    Quote Originally Posted by stanav View Post
    As long as all your dates having the same format dd.MM.yyyy then that code will work. If any of the dates is in short format, for example 22.4.2009 or 1.2.2010 instead of 22.04.2009 or 01.02.2010 then that code will not work.
    Thats right. It all depends on the data and the assumptions you can make and he would know that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width