left(string, length) or right(string, length)?

Discussion in 'ASP .Net' started by Sam, Feb 17, 2005.

  1. Sam

    Sam Guest

    I want to divide character into 2 section.

    Example, 200412 divided into 2004 in A block and 12 in B block.

    Please advise how to use left(string, length) or right(string, length) for above request.

    Many thanks in advance.
    Sam, Feb 17, 2005
    #1
    1. Advertising

  2. Sam

    Karl Seguin Guest

    Sam,
    These questions are always hard to answer because we aren't 100% clear on how you want to split it. Will it always be the first 4 characters in the first block? Or will it always be the last 2 in the 2nd block? Or are they the same because the block will always be 6 characters?

    Anyways, assuming it'll always be XXXXYY then I'd do:

    Dim originalString As String = "200412"
    Dim aBlock As String = originalString.Substring(0, 4)
    Dim bBlock As String = originalString.Substring(4)

    I prefer subString over left and right because it's more .net frameworkish (that is it'll work in C# as well)

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Sam" <> wrote in message news:...
    I want to divide character into 2 section.

    Example, 200412 divided into 2004 in A block and 12 in B block.

    Please advise how to use left(string, length) or right(string, length) for above request.

    Many thanks in advance.
    Karl Seguin, Feb 17, 2005
    #2
    1. Advertising

  3. Sam

    Sam Guest

    It's mean aBlock is 2004 and bBlock is 12?

    Yes, I want it split off, 2004 and 12 of 200412.

    Do I need to declare something before originalString.Substring? Explicit Options?

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:e%...
    Sam,
    These questions are always hard to answer because we aren't 100% clear on how you want to split it. Will it always be the first 4 characters in the first block? Or will it always be the last 2 in the 2nd block? Or are they the same because the block will always be 6 characters?

    Anyways, assuming it'll always be XXXXYY then I'd do:

    Dim originalString As String = "200412"
    Dim aBlock As String = originalString.Substring(0, 4)
    Dim bBlock As String = originalString.Substring(4)

    I prefer subString over left and right because it's more .net frameworkish (that is it'll work in C# as well)

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Sam" <> wrote in message news:...
    I want to divide character into 2 section.

    Example, 200412 divided into 2004 in A block and 12 in B block.

    Please advise how to use left(string, length) or right(string, length) for above request.

    Many thanks in advance.
    Sam, Feb 17, 2005
    #3
  4. Sam

    Karl Seguin Guest

    Sam:
    Everything in the code I gave you is explicitely declared....I'm making use of three variables "originalString" , "aBlock" and "bBlock" Option Explicit is automatically turned on in VB.Net

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Sam" <> wrote in message news:%...
    It's mean aBlock is 2004 and bBlock is 12?

    Yes, I want it split off, 2004 and 12 of 200412.

    Do I need to declare something before originalString.Substring? Explicit Options?

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:e%...
    Sam,
    These questions are always hard to answer because we aren't 100% clear on how you want to split it. Will it always be the first 4 characters in the first block? Or will it always be the last 2 in the 2nd block? Or are they the same because the block will always be 6 characters?

    Anyways, assuming it'll always be XXXXYY then I'd do:

    Dim originalString As String = "200412"
    Dim aBlock As String = originalString.Substring(0, 4)
    Dim bBlock As String = originalString.Substring(4)

    I prefer subString over left and right because it's more .net frameworkish (that is it'll work in C# as well)

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Sam" <> wrote in message news:...
    I want to divide character into 2 section.

    Example, 200412 divided into 2004 in A block and 12 in B block.

    Please advise how to use left(string, length) or right(string, length) for above request.

    Many thanks in advance.
    Karl Seguin, Feb 17, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmlzaG95?=
    Replies:
    0
    Views:
    966
    =?Utf-8?B?QmlzaG95?=
    Dec 28, 2006
  2. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help on table align on left of page vs left hanging indent

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Jul 10, 2007, in forum: XML
    Replies:
    2
    Views:
    988
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    Jul 16, 2007
  3. pc
    Replies:
    2
    Views:
    1,294
    crisgoogle
    Jun 8, 2011
  4. lawrence
    Replies:
    13
    Views:
    287
    Thomas 'PointedEars' Lahn
    Sep 4, 2004
  5. Oran
    Replies:
    2
    Views:
    515
Loading...

Share This Page