I didn't know commas were letters

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

I didn't know commas were letters

Post by richmond62 » Wed May 14, 2025 2:41 pm

Screenshot 2025-05-14 at 16.39.31.png
-
Can anyone tell me why my punctuation is getting lost?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: I didn't know commas were letters

Post by FourthWorld » Wed May 14, 2025 4:08 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: I didn't know commas were letters

Post by richmond62 » Wed May 14, 2025 4:33 pm

Hmm . . . But "|".

More extensive reply elsewhere. 8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: I didn't know commas were letters

Post by dunbarx » Wed May 14, 2025 5:05 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: I didn't know commas were letters

Post by richmond62 » Wed May 14, 2025 5:46 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: I didn't know commas were letters

Post by dunbarx » Wed May 14, 2025 9:34 pm

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

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: I didn't know commas were letters

Post by SparkOut » Wed May 14, 2025 11:30 pm

richmond62 wrote:
Wed May 14, 2025 5:46 pm
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.
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).
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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: I didn't know commas were letters

Post by dunbarx » Thu May 15, 2025 1:02 am

Richmond, Sparkout.

I am lost. What is the issue here? I cannot read the handler in Richmond's first post.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: I didn't know commas were letters

Post by richmond62 » Thu May 15, 2025 9:03 am

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:

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
-
SShot 2025-05-15 at 11.03.35.png
SShot 2025-05-15 at 11.03.35.png (12.57 KiB) Viewed 4899 times
-

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
-
SShot 2025-05-15 at 11.03.44.png
SShot 2025-05-15 at 11.03.44.png (13.91 KiB) Viewed 4899 times
-
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
-
SShot 2025-05-15 at 11.03.51.png
SShot 2025-05-15 at 11.03.51.png (12.61 KiB) Viewed 4899 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: I didn't know commas were letters

Post by richmond62 » Thu May 15, 2025 9:15 am

Because trueWord treats "|" as something to be excluded one cannot then use it as an itemDelimiter.

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: I didn't know commas were letters

Post by stam » Thu May 15, 2025 12:15 pm

richmond62 wrote:
Thu May 15, 2025 9:15 am
Because trueWord treats "|" as something to be excluded one cannot then use it as an itemDelimiter.
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?

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.

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: I didn't know commas were letters

Post by stam » Thu May 15, 2025 12:27 pm

Specifically the command

Code: Select all

ReplaceText(sourceText, “\|\w*”, “”)

Will remove all pipe symbols and the word that follows the pipes.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: I didn't know commas were letters

Post by richmond62 » Thu May 15, 2025 12:28 pm

Yes, it will, but it will not allow you to perform further operations on those words.

stam
Posts: 3061
Joined: Sun Jun 04, 2006 9:39 pm

Re: I didn't know commas were letters

Post by stam » Thu May 15, 2025 12:38 pm

richmond62 wrote:
Thu May 15, 2025 12:28 pm
Yes, it will, but it will not allow you to perform further operations on those words.
Literally every exchange with you Richmond is an exercise in futility.

If that’s what you wanted to do, how does that come through on your previous post:
richmond62 wrote:
Thu May 15, 2025 9:03 am
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.
My answer is the solution to the question you explicitly asked.
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?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: I didn't know commas were letters

Post by richmond62 » Thu May 15, 2025 1:37 pm

It’s not like you’re a beginner, so why do you ask questions like one?
Aah: what constitutes a beginner?

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.

Post Reply