I didn't know commas were letters
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
I didn't know commas were letters
Can anyone tell me why my punctuation is getting lost?
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: I didn't know commas were letters
HyperCard established a weird definition for "word" being anything in between spaces, then making it weirder by adding an exception where everything in between double quotes is a single word, regardless how many words are between the quotes.
Several years ago Mark Waddingham created another chuck type to allow us to parse true words. I suggested we name the chunk type trueWord, and he ran with that.
So replacing "word" with "trueWord" there may do what you want.
Several years ago Mark Waddingham created another chuck type to allow us to parse true words. I suggested we name the chunk type trueWord, and he ran with that.
So replacing "word" with "trueWord" there may do what you want.
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
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: I didn't know commas were letters
Hmm . . . But "|".
More extensive reply elsewhere.
More extensive reply elsewhere.

Re: I didn't know commas were letters
Richmond.
The comments notwithstanding, is title of your post at all pertinent? A comma is a character, and whether or not it is its own word is a matter of how it lives within the body of text. What were you really asking?
Craig
The comments notwithstanding, is title of your post at all pertinent? A comma is a character, and whether or not it is its own word is a matter of how it lives within the body of text. What were you really asking?
Craig
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: I didn't know commas were letters
I am asking how to count words, and then, having deleted several from a textField how to put them into another textField with commas, and other punctuation marks intact.
Re: I didn't know commas were letters
Richmond.
Still not sure what you mean. If you have "my dog has fleas", that is four words. With "my dog, has, fleas", that is also four words. And if you have "my dog , has , fleas" that is six words. Right?
If you have some words in a textField, and you delete them, they are gone. You surely did not mean that. But if you cut them and put them into another textField they come over intact, exactly as they were. Er, right?
What is the problem with punctuation?
Craig
Still not sure what you mean. If you have "my dog has fleas", that is four words. With "my dog, has, fleas", that is also four words. And if you have "my dog , has , fleas" that is six words. Right?
If you have some words in a textField, and you delete them, they are gone. You surely did not mean that. But if you cut them and put them into another textField they come over intact, exactly as they were. Er, right?

What is the problem with punctuation?
Craig
Re: I didn't know commas were letters
The commas are not treated as letters, what you are doing is copying words only (without punctuation, since the commas are not part of the word).richmond62 wrote: ↑Wed May 14, 2025 5:46 pmI am asking how to count words, and then, having deleted several from a textField how to put them into another textField with commas, and other punctuation marks intact.
Try putting the entire field contents into the destination field, so your punctuation will be included in the outcome. Then in your loop through the words (change this loop to target the destination field) to check for the pipe symbol, delete item 2 of word KOUNT of the field You'd probably need to do a blanket replace for the pipe symbol with empty to tidy up at the end.
Re: I didn't know commas were letters
Richmond, Sparkout.
I am lost. What is the issue here? I cannot read the handler in Richmond's first post.
Craig
I am lost. What is the issue here? I cannot read the handler in Richmond's first post.
Craig
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: I didn't know commas were letters
OK, OK, I shall go through 'my problem' (well, this one) step-by-step:
I have some text that looks like this:
I like cheese and pickle, I like cheese|pickle, I like sausages|mustard
I should like it to end up like this:
I like cheese and pickle, I like cheese, I like sausages
Where the second part of a word that has a "|" in it is deleted, BUT and punctuation is preserved.
THIS lost the punctuation:
-
-
This lost all sorts of things:
-
-
This did what I wanted, but as far as I am concerned it seems fudgey:
-
I have some text that looks like this:
I like cheese and pickle, I like cheese|pickle, I like sausages|mustard
I should like it to end up like this:
I like cheese and pickle, I like cheese, I like sausages
Where the second part of a word that has a "|" in it is deleted, BUT and punctuation is preserved.
THIS lost the punctuation:
Code: Select all
on mouseup
put empty into fld "f2"
put the number of words in fld "f1" into NDICK
put 1 into KOUNT
repeat until KOUNT > NDICK
if word KOUNT of fld "f1" contains "|" then
put word KOUNT of fld "f1" into DIX
set the itemDelimiter to "|"
put item 1 of DIX into DUX
put " " & DUX after fld "f2"
else
put " " & word KOUNT of fld "f1" after fld "f2"
end if
add 1 to KOUNT
end repeat
end mouseup
This lost all sorts of things:
Code: Select all
on mouseup
put empty into fld "f2"
put the number of trueWords in fld "f1" into NDICK
put 1 into KOUNT
repeat until KOUNT > NDICK
if trueWord KOUNT of fld "f1" contains "|" then
put trueWord KOUNT of fld "f1" into DIX
set the itemDelimiter to "|"
put item 1 of DIX into DUX
put " " & DUX after fld "f2"
else
put " " & trueWord KOUNT of fld "f1" after fld "f2"
end if
add 1 to KOUNT
end repeat
end mouseup
This did what I wanted, but as far as I am concerned it seems fudgey:
Code: Select all
on mouseup
put empty into fld "f2"
put the number of words in fld "f1" into NDICK
put 1 into KOUNT
repeat until KOUNT > NDICK
if word KOUNT of fld "f1" contains "|" then
put word KOUNT of fld "f1" into DIX
set the itemDelimiter to "|"
put item 1 of DIX into DUX
if item 2 of DIX contains "," then
put "," after DUX
end if
put " " & DUX after fld "f2"
else
put " " & word KOUNT of fld "f1" after fld "f2"
end if
add 1 to KOUNT
end repeat
end mouseup
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: I didn't know commas were letters
Because trueWord treats "|" as something to be excluded one cannot then use it as an itemDelimiter.
Re: I didn't know commas were letters
Are you sure you cannot use the pipe symbol “|” as an itemDelimiter? With the same logic you shouldn’t be able to use comma as an itemDelimiter, which is patently incorrect. Its is a char and as far as I’m aware itemDelimiters are chars, not trueWords, I’m not sure how you draw a connection between itemDelimiter and trueWord?richmond62 wrote: ↑Thu May 15, 2025 9:15 amBecause trueWord treats "|" as something to be excluded one cannot then use it as an itemDelimiter.
If you want to just delete the pipe symbol and the word following this then just use replaceText() - it uses regex which makes finding the pattern pipe+word trivial. One single command would remove all instances without affecting punctuation and without a loop.
Re: I didn't know commas were letters
Specifically the command
Will remove all pipe symbols and the word that follows the pipes.
Code: Select all
ReplaceText(sourceText, “\|\w*”, “”)
Will remove all pipe symbols and the word that follows the pipes.
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: I didn't know commas were letters
Yes, it will, but it will not allow you to perform further operations on those words.
Re: I didn't know commas were letters
Literally every exchange with you Richmond is an exercise in futility.richmond62 wrote: ↑Thu May 15, 2025 12:28 pmYes, it will, but it will not allow you to perform further operations on those words.
If that’s what you wanted to do, how does that come through on your previous post:
My answer is the solution to the question you explicitly asked.richmond62 wrote: ↑Thu May 15, 2025 9:03 amOK, OK, I shall go through 'my problem' (well, this one) step-by-step:
I have some text that looks like this:
I like cheese and pickle, I like cheese|pickle, I like sausages|mustard
I should like it to end up like this:
I like cheese and pickle, I like cheese, I like sausages
Where the second part of a word that has a "|" in it is deleted, BUT and punctuation is preserved.
It’s weird that you then decide it wasn’t what you wanted after all
Just decide what it is you want and actually state it. .
In any case all is easily doable with regex: you can locate the word, the offsets within the source text and replace them all.
It’s not like you’re a beginner, so why do you ask questions like one?
-
- Livecode Opensource Backer
- Posts: 10078
- Joined: Fri Feb 19, 2010 10:17 am
Re: I didn't know commas were letters
Aah: what constitutes a beginner?It’s not like you’re a beginner, so why do you ask questions like one?
I'll bet you're fairly useless when it comes to working out how to implement conjunct consonants in Unicode inwith LiveCode.
The FACT is that, while I have worked with xTalk (Hypercard and onwards) for 32 years, I have NOT worked with those versions of xTalk in ALL areas that the language can deal with, any more than you have.