Link to home
Start Free TrialLog in
Avatar of Hojoformo
Hojoformo

asked on

Field Split Programming Questions

I have a text field that contains multiple Catagories each is identified by ';' semicolon following the catagory name as follows:

CATEGORY1;This text for catagory 1. CATAGORY2; This text for catagory 2. CATAGORY 3; This is text for catagory 3.

I need to separate each Catagory into separate fields as follows:

FLD1 = CATEGORY1;This text for catagory 1
FLD2 =  CATAGORY2; This text for catagory 2.
FLD 3 = CATAGORY 3; This is text for catagory 3.

Any suggestions on how I can do this?  I am currently using the split command but this is giving the following results:

FLD1 = CATEGORY1
FLD2 =  This text for catagory 1[][]CATAGORY2
FLD 3 = This text for catagory 2.[][]CATAGORY 3
FLD 4 = This is text for catagory 3.

Here is my code:

 For Each dr In dt.Rows
        tAuditComments = Convert.ToString(dr("TRIPLEMEMO")).ToString()
        Fields = tAuditComments.Split(";"c) +
NEXT
Avatar of apresto
apresto
Flag of Italy image

Hi Hojoformo,

split by '.'

Apresto
You are splitting by ; but the lines are seperated by the fullstops by the looks of it
Avatar of Hojoformo
Hojoformo

ASKER

I can not split by period becuase there can be multiple sentences per catagory as follows:

CATEGORY1;This text for catagory 1. This more text for catagory 1. CATAGORY2; This text for catagory 2. CATAGORY 3; This is text for catagory 3.
ok, are you able to change the splitter symbol to something else, like a #, as there is no correlation to the splitting at the moment

so:
CATEGORY1;This text for catagory 1. This more text for catagory 1#
CATAGORY2; This text for catagory 2#
CATAGORY 3; This is text for catagory 3#

then you can split on #
SOLUTION
Avatar of apresto
apresto
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The approach that will work for your scenario is to find the index of CATEGORY and then find the index of the "." before it (using string.indexof). You'll then need to split the string using string.substring.

A word of caution... the first pass through will fail, since there is no . immediately before category1, so you'll need to accomodate this.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fernando Soto
Hi Hojoformo;

I have a couple of questions for you.

1. Is the Delimiter "CATAGORY" always in capital leters?
2. Is it always immediately followed by a numeric value, no white space characters? For example "CATAGORY99" and NOT "CATAGORY 99".
3. Are the lines terminated with a carrage return and line feed or is it one continuous line of data?

Fernando
Fernando

I hoped we might see you ;-)

It may just be a typo, but I noted that, in the example, the first one was spelled with an "E" - CATEGORY - but the latter two with an "A" - CATAGORY.

Roger
Hi Roger;

I like your solution to the problem. ;=)

Fernando