Splitting Data on same line
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Splitting Data on same line
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!
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
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!
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!

Re: Splitting Data on same line
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'.
Hope that helps you out some.
In LIvecode, you can set this to almost anything, but in your example, you'd likely want to set it to 'comma'.
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.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
Hope that helps you out some.

Re: Splitting Data on same line
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
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
@bogs
Thanks!
So something like
set the itemdelimiter to comma
Where would I put this in my code?
Thanks!
So something like
set the itemdelimiter to comma
Where would I put this in my code?
Re: Splitting Data on same line
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
...
Too late, mate, I wrote "... in a first posting".

Best
Klaus
Re: Splitting Data on same line
That is correct, something like that would be ideal
Re: Splitting Data on same line
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 -
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
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
Heh, I see Klaus beat me to it with a much more specific answer


-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Splitting Data on same line
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Splitting Data on same line
Thanks so much the code worked, Now I just need a litte bit of help with posting to output.Klaus wrote: ↑Thu Feb 07, 2019 11:26 pmIf I understand the task correctly, you need something like this:Et voila, two arrays with the appropriate content (hopefully).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 ...
Too late, mate, I wrote "... in a first posting".![]()
Best
Klaus
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
Actually, I got it working.
Everyone thank you so much for the help!
Everyone thank you so much for the help!