Splitting Data on same line

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
CalumS
Posts: 9
Joined: Thu Feb 07, 2019 10:31 pm

Splitting Data on same line

Post by CalumS »

I'm doing a school project in school and my teacher does not even know how do to this.

I have data like the following:
Watwick,5
Welcombe Mouth,5
Wells - next - the - Sea,1
Wembury,1
Wemyss Bay,5
West Angle Bay,1
West-Bay,1
West Kirby,1
West Mersea,1
West Runton,5
West Sandwick Beach,1
West Voe Sands,1
West Wittering,1

I need anything before the first comma to go into an array/record structure called 'Name' than anything after the comma to go into an array/record structure into Rating

She has only taught us how to do for data like:

1
2
4
6
3

Now data that has to be split on the same line, any help would be great!
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Splitting Data on same line

Post by Klaus »

Hi Calum,

welcome to the forum!

Déjà vue?
viewtopic.php?f=7&t=32138

Best

Klaus

P.S.
A little "Hello" or something will not hurt in a first posting! 8)
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Splitting Data on same line

Post by bogs »

In the dictionary, look up 'itemDelimiter'.

In LIvecode, you can set this to almost anything, but in your example, you'd likely want to set it to 'comma'.
I need anything before the first comma to go into an array/record structure called 'Name' than anything after the comma to go into an array/record structure into Rating
In this case, after setting the itemDelimiter, you can choose the parts of the record by 'Item', so the first item would be anything before the first comma.

Hope that helps you out some.
Image
CalumS
Posts: 9
Joined: Thu Feb 07, 2019 10:31 pm

Re: Splitting Data on same line

Post by CalumS »

Sorry, just in a rush to figure this out.
I figured out that the code was designed for having one set of data on each line.

Any idea how I could do it with the data I have?

Hello btw :)
CalumS
Posts: 9
Joined: Thu Feb 07, 2019 10:31 pm

Re: Splitting Data on same line

Post by CalumS »

@bogs

Thanks!
So something like

set the itemdelimiter to comma

Where would I put this in my code?
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Splitting Data on same line

Post by Klaus »

CalumS wrote: Thu Feb 07, 2019 11:15 pm Any idea how I could do it with the data I have?
If I understand the task correctly, you need something like this:

Code: Select all

...
## The default item delimiter = COMMA, so need to set it here!
## tData is the list with the "city,number" pairs
repeat with i = 1 to the num of lines of tData
  put item 1 of line i of tData into tNameArray[i]
  put item 2 of line i of tData into tRatingArray[i]
end repeat
...
Et voila, two arrays with the appropriate content (hopefully).
CalumS wrote: Thu Feb 07, 2019 11:15 pmHello btw :)
Too late, mate, I wrote "... in a first posting". 8)

Best

Klaus
CalumS
Posts: 9
Joined: Thu Feb 07, 2019 10:31 pm

Re: Splitting Data on same line

Post by CalumS »

That is correct, something like that would be ideal
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Splitting Data on same line

Post by bogs »

Somewhere before you start manipulating the data in the handler your using (sorry I can't be a lot more detailed, almost all of this really depends on personal preference).

Psuedo-code would look something like -

Code: Select all

/* assuming for a moment your using a button to put the data into  a variable or field
    you might use the 'on mouseUp' handler... */
on mouseUp
	set the itemDelimiter to comma
	repeat for each line x in {theData_Container}
		put item 1 of x into {yourArray, yourKey}
	end repeat
	// any other operations you need done...
end mouseUp
The above isn't tested nor even very specific, and there are LOTS of other ways to handle something like this, but it should give you a start.

Heh, I see Klaus beat me to it with a much more specific answer :)
Image
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Splitting Data on same line

Post by Klaus »

CalumS wrote: Thu Feb 07, 2019 11:27 pm That is correct, something like that would be ideal
Well, then just take it, it's free! 8)
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10105
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Splitting Data on same line

Post by FourthWorld »

Why does the structure need to be an array, specifically?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
CalumS
Posts: 9
Joined: Thu Feb 07, 2019 10:31 pm

Re: Splitting Data on same line

Post by CalumS »

Klaus wrote: Thu Feb 07, 2019 11:26 pm
CalumS wrote: Thu Feb 07, 2019 11:15 pm Any idea how I could do it with the data I have?
If I understand the task correctly, you need something like this:

Code: Select all

...
## The default item delimiter = COMMA, so need to set it here!
## tData is the list with the "city,number" pairs
repeat with i = 1 to the num of lines of tData
  put item 1 of line i of tData into tNameArray[i]
  put item 2 of line i of tData into tRatingArray[i]
end repeat
...
Et voila, two arrays with the appropriate content (hopefully).
CalumS wrote: Thu Feb 07, 2019 11:15 pmHello btw :)
Too late, mate, I wrote "... in a first posting". 8)

Best

Klaus
Thanks so much the code worked, Now I just need a litte bit of help with posting to output.

repeat with i = 1 to number of lines in tNameArray
Put tRatingArray into line i of field "output"
end repeat

That is the code I am using, do you see anything wrong with it?
CalumS
Posts: 9
Joined: Thu Feb 07, 2019 10:31 pm

Re: Splitting Data on same line

Post by CalumS »

Actually, I got it working.
Everyone thank you so much for the help!
Post Reply