Page 1 of 1

Splitting Data on same line

Posted: Thu Feb 07, 2019 10:53 pm
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!

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:12 pm
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)

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:14 pm
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.

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:15 pm
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 :)

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:18 pm
by CalumS
@bogs

Thanks!
So something like

set the itemdelimiter to comma

Where would I put this in my code?

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:26 pm
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 pm
Hello btw :)
Too late, mate, I wrote "... in a first posting". 8)

Best

Klaus

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:27 pm
by CalumS
That is correct, something like that would be ideal

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:29 pm
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 :)

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:30 pm
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)

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:35 pm
by FourthWorld
Why does the structure need to be an array, specifically?

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:51 pm
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 pm
Hello 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?

Re: Splitting Data on same line

Posted: Thu Feb 07, 2019 11:53 pm
by CalumS
Actually, I got it working.
Everyone thank you so much for the help!