Solved

Field Split Programming Questions

Posted on 2006-07-17
10
197 Views
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:

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
0
Comment
Question by:Hojoformo
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 23

Expert Comment

by:apresto
Comment Utility
Hi Hojoformo,

split by '.'

Apresto
0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
You are splitting by ; but the lines are seperated by the fullstops by the looks of it
0
 

Author Comment

by:Hojoformo
Comment Utility
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.
0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
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 #
0
 
LVL 23

Assisted Solution

by:apresto
apresto earned 100 total points
Comment Utility
also could you delete the duplicate question you have posted in ASP.net otherwise the moderators will tell you to do so.  You can create a pointer question in the asp.net 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)
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 24

Expert Comment

by:Jeff Certain
Comment Utility
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.

0
 
LVL 34

Accepted Solution

by:
Sancler earned 400 total points
Comment Utility
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)
        Next

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.

Roger
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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
0
 
LVL 34

Expert Comment

by:Sancler
Comment Utility
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
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Hi Roger;

I like your solution to the problem. ;=)

Fernando
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now