Removing Nulls from strings

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

stam
Posts: 2633
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Removing Nulls from strings

Post by stam » Thu Apr 14, 2022 10:52 am

richmond62 wrote:
Thu Apr 14, 2022 10:40 am
Just to throw a spanner in the works <snip>
Perhaps read a few posts up?
There are at least 5 posts discussing this - it's not a bug and not an issue with the "?" char.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Removing Nulls from strings

Post by richmond62 » Thu Apr 14, 2022 10:57 am

OK: been out of focus recently:

got badly bogged down sorting out things with some Ukrainian refugees' children last weekend.

Unfortunately, having only worked over the last 18 years with what my Granny would call, "Children from good families." I had overlooked the possibility that some of these Ukrainian kids might be right whatsits: and of 12, 3 turned out to be teenage yobs of the worst sort: and, predictably perhaps, their parents suffered from a bad case of 'entitlement', meaning I had to spend quite some time explaining that while I was offering 12 free places in my language school I was not going to take their OIKS . . . one black eye later (mine) and one Ukrainian father in police custody (I will not press charges: I think that a night in police cells here was more than enough . . . LOL), things have calmed down: even if I do look a bit of a ruffian. :D

Luckily all the other Ukrainian children, and their Mums and Dads,have turned out to be lovely. 8)

stam
Posts: 2633
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Removing Nulls from strings

Post by stam » Thu Apr 14, 2022 11:00 am

Ooof that sounds tough...
Good on you though Richmond, that's praiseworthy...

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Removing Nulls from strings

Post by Simon Knight » Thu Apr 14, 2022 11:14 am

# Stam,

Unfortunately while your code is quite correct there is no simple method of feeding it data. The problem is how do you get it a list of filenames that include the newline character ? It cannot be achieved using Livecode Files as this uses the newline character as the item separator. This is exactly the problem discussed in the link I quoted above. The tools that are used will in certain circumstances return incorrect data. Remember with my subject files Livecode never sees the question mark also there is a very good chance that the question mark is a place holder for any number of strange characters that are quite legal in Unix file names.

The work around will be triggered following an error reported in the result. In my case it will be "can't find file" which lets face it is odd because I only have the name because Livecode passed it to me. So psudo code :

Code: Select all

If the result is "can't find file" then
put item n+1 of tList into tNextFileName
put tOldFileName & tNextFileName into tCorrectedOldFileName
if there is a file tCorrectedOldFileName then
rename tCorrectedOldFileName to tNewFileName
add one to n
end if
end if
It will take more than this as tNewFileNAme will also have to be corrected as it will be based on duff data, but it shows the idea. Another way will be to seek an extension but I am not sure if all files have extensions. MacOS use to frown on extensions as it had a filetype code. So it is quite a tricky issue with no simple answer.

S
best wishes
Skids

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Removing Nulls from strings

Post by Simon Knight » Thu Apr 14, 2022 11:22 am

got badly bogged down sorting out things with some Ukrainian refugees' children last weekend.
Ouch! Sorry to here that you were having problems - strange how people bite the hand that feeds them. What age is the father? I thought they were suppose to remain in Ukraine and fight if they were between 18 and 60?

S
best wishes
Skids

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Removing Nulls from strings

Post by richmond62 » Thu Apr 14, 2022 11:44 am

they were suppose to remain in Ukraine and fight if they were between 18 and 60?
About 45: mind you, I'd be scared if he had a gun in his hand, even if, theoretically, he were on my side.

Ukrainians are just as everyone else: they have their fair share of "that type of person."

The ONLY problem was that the 19 year old (only selected because he was bilingual in Ukrainian and Bulgarian)
who was delegated to bring kids along to my school, being only 19, did not have the necessary social filters
to work out the difference between YOBS and DECENT people. Never mind, he went back to the Consulate with
his tail well between his legs, and then the Consul gave him a good wigging.

And, as I have had far worse than a black eye before in my life (plus I look rather dashing in my new role as the Pirate
King of Plovdiv), this does not fuss me unduly: just makes me feel a bit tired: and, as my wife says, "At 60 you should not
have to deal with that kind of crap." I'll tell you something: there are many, many people well over 60 who have to deal
with far worse types of crap every day of their lives: so I am not complaining. :)

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Removing Nulls from strings

Post by Simon Knight » Thu Apr 14, 2022 11:57 am

Pirate King of Plovdiv
would make a great forum name!

I agree that you should not have to deal with that sort of crap but as you said "they" exist everywhere. Good luck with the twelve you are teaching.

We have a friend who is expecting two sisters with children in about a weeks time UK border force permitting. They sound honest decent and terrified.

S
best wishes
Skids

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Removing Nulls from strings

Post by richmond62 » Thu Apr 14, 2022 1:16 pm

Even those Yobby kids are running from bombs; so the whole situation is far, far
worse than a biff in the eye. And how much of those yobby kids' behaviour was
'normal' for them, and how much a defence mechanism against some sort of perceived
threat is a funny question.

What those 2 sisters with children need is a place of safety, and if you or your friend
can offer that, that should be enough.

stam
Posts: 2633
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Removing Nulls from strings

Post by stam » Thu Apr 14, 2022 5:32 pm

Simon Knight wrote:
Thu Apr 14, 2022 11:14 am
# Stam,

Unfortunately while your code is quite correct there is no simple method of feeding it data. The problem is how do you get it a list of filenames that include the newline character ? It cannot be achieved using Livecode Files as this uses the newline character as the item separator. This is exactly the problem discussed in the link I quoted above. The tools that are used will in certain circumstances return incorrect data. Remember with my subject files Livecode never sees the question mark also there is a very good chance that the question mark is a place holder for any number of strange characters that are quite legal in Unix file names.
If it were me, i'd run through the the list of real or broken filenames and if there was a char with ascii code < 32, i'd try to rename *all* the files then try again. It would probably mean having to use console commands to do the renaming on a unix level but that would be a matter of consulting our dear friend Mr Google ;)

S.

mainmein39
Posts: 1
Joined: Wed May 11, 2022 11:02 am

Re: Removing Nulls from strings

Post by mainmein39 » Wed May 11, 2022 11:24 am

I see that "replaceText" lives strictly within regex. But, since "null' is a constant in LC, then could not the OP simply use the "replace" command?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Removing Nulls from strings

Post by richmond62 » Wed May 11, 2022 11:59 am

As the null is nothing I wonder what is going to be replaced.

stam
Posts: 2633
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Removing Nulls from strings

Post by stam » Wed May 11, 2022 2:39 pm

mainmein39 wrote:
Wed May 11, 2022 11:24 am
I see that "replaceText" lives strictly within regex. But, since "null' is a constant in LC, then could not the OP simply use the "replace" command?
Yes @mainmein39, the OP could and in actual fact has - the only problem is that no one actually reads the long threads they respond to.

For example, in page 1 of this thread:
stam wrote:
Mon Apr 11, 2022 11:15 am
No need for all that Richmond, Simon already has a working version of this that is simply one line:

Code: Select all

replace null with "" in tProblem
his issue was that replaceText(tProblem, null, "") doesn't work. That's because the find criterion is regex and not free text or keywords, so the syntactically correct way of doing this is

Code: Select all

replaceText(tProblem, "\0", "")

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Removing Nulls from strings

Post by Simon Knight » Wed May 11, 2022 4:43 pm

As the null is nothing I wonder what is going to be replaced.
That will be the character ASCII 00.

For Example Olympus and some other cameras terminate the text string which stores the makers name in their raw files with a null character. Initially my code attempted to use the extracted name in a file name. Unfortunately the rename command stops at the null character as Apple OS does not allow null characters in filenames so my cunning rename failed.

As others have hinted this thread was a case of "Read the Dictionary" - my bad!

S
best wishes
Skids

Post Reply

Return to “Talking LiveCode”