• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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
0
Hojoformo
Asked:
Hojoformo
  • 4
  • 2
  • 2
  • +2
2 Solutions
 
aprestoCommented:
Hi Hojoformo,

split by '.'

Apresto
0
 
aprestoCommented:
You are splitting by ; but the lines are seperated by the fullstops by the looks of it
0
 
HojoformoAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
aprestoCommented:
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
 
aprestoCommented:
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
 
Jeff CertainCommented:
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
 
SanclerCommented:
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
 
Fernando SotoCommented:
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
 
SanclerCommented:
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
 
Fernando SotoCommented:
Hi Roger;

I like your solution to the problem. ;=)

Fernando
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now