Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > left(string, length) or right(string, length)?

Reply
Thread Tools

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

 
 
Sam
Guest
Posts: n/a
 
      02-17-2005
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.
 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      02-17-2005
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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.
 
Reply With Quote
 
 
 
 
Sam
Guest
Posts: n/a
 
      02-17-2005
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%(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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.
 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      02-17-2005
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" <(E-Mail Removed)> wrote in message news:%(E-Mail Removed)...
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%(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments