Field Split Programming Questions

Posted on 2006-07-17
Last Modified: 2010-04-23
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:

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) +
Question by:Hojoformo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
LVL 23

Expert Comment

ID: 17121515
Hi Hojoformo,

split by '.'

LVL 23

Expert Comment

ID: 17121527
You are splitting by ; but the lines are seperated by the fullstops by the looks of it

Author Comment

ID: 17121532
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.
Technology Partners: 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!

LVL 23

Expert Comment

ID: 17121547
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

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 #
LVL 23

Assisted Solution

apresto earned 100 total points
ID: 17121557
also could you delete the duplicate question you have posted in otherwise the moderators will tell you to do so.  You can create a pointer question in the topic area pointing to this question, you can post multiople questions aslong as they do not exceed 500 points.  Just tellin gyou so that it saves the mods and clean up staff some time, as you can just hit the delete link :o)
LVL 24

Expert Comment

by:Jeff Certain
ID: 17121951
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.

LVL 34

Accepted Solution

Sancler earned 400 total points
ID: 17122029
Try this

Imports System.Text.RegularExpressions

        Dim r As New Regex("CAT")
        Dim teststring As String = "CATEGORY1;This text for catagory 1. CATAGORY2; This text for catagory 2. CATAGORY 3; This is text for catagory 3."
        Dim parts() As String = r.Split(teststring)
        For Each part As String In parts
            Debug.WriteLine("CAT" & part)

This splits on CAT (specifically, upper case) using regex (because string.split will only take single characters and it doesn't look like a single character would be sufficient for your scenario).  But simple regex.split leaves out from the result the string used for the split, so this demo adds it back.  I'm sure there's more elegant ways of doing it with regex, but perhaps FernandoSoto - who's the king in this TA so far as Regex is concerned - will chip in with something better.

LVL 63

Expert Comment

by:Fernando Soto
ID: 17122077
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?

LVL 34

Expert Comment

ID: 17122331

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.

LVL 63

Expert Comment

by:Fernando Soto
ID: 17122490
Hi Roger;

I like your solution to the problem. ;=)


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question