12-29-2022, 02:15 PM
(12-29-2022, 08:30 AM)SMcNeill Wrote: There's a couple of small glitches in this, that you might want to take a look at and fix, @George McGinn.
First, there's the whole need to set the compiler to allow -fpermissive so this will run. Types don't match properly, so you might want to tweak them a little.
Second is this alters the original string, corrupting it, as shown below:
Code: (Select All)Declare CustomType Library "removeStr"
Function __REMOVESPACES$ Alias string_remove_chr (qString$, charValue$)
End Declare
check$ = "This is a string that we're going to check to see how long it would take to remove the spaces from."
Print check$
Print "The length of our test string is:"; Len(check$)
new$ = __REMOVESPACES$(check$, " ")
Print check$, Len(check$)
End
check$ remains the same length as previously, but the left side of it now mirrors new$. You might want to assign your string to a temp string and process it, rather than process the original as you go along, to preserve it.
The reqason your value is corrupted is because you need to terminate a variable with CHR$(0). Line new$ = __REMOVESPACES$(check$, " ") needs to be new$ = __REMOVESPACES$(check$+CHR$(0), " ") - It seems that when you pass variables, you need to tell it when it ends. Literals do not have that problem.
Without a NULL terminator, C does not know when your variable ends. So it keeps going.
If you want to, you could leave your code as-is, but do this:
Code: (Select All)
check$ = "This is a string that we're going to check to see how long it would take to remove the spaces from." + CHR$(0)
However, doing the above messes up the QB64 PRINT statement results.
—————————————————————————————
George McGinn
Theoretical/Applied Computer Science Specialist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
Society of American Baseball Research
George McGinn
Theoretical/Applied Computer Science Specialist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
Society of American Baseball Research