Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove Spaces (or other characters) from a String
#7
(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.  Wink

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
Reply


Messages In This Thread
RE: Remove Spaces (or other characters) from a String - by George McGinn - 12-29-2022, 02:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  STRING$ empowered with StringPatternFilling TempodiBasic 6 1,236 05-09-2025, 06:00 PM
Last Post: TempodiBasic
  Split String to Array Using Strtok (Attempt #2) SpriggsySpriggs 0 544 12-17-2024, 06:37 PM
Last Post: SpriggsySpriggs
  Remove Remarks for Programs Pete 17 2,972 10-27-2024, 02:22 PM
Last Post: Dimster
  Variable characters eoredson 7 1,520 10-21-2024, 02:55 AM
Last Post: eoredson
  PrintW - print a long string, breaking it at the last space or hyphen before col. 79 TDarcos 21 4,082 04-22-2024, 09:52 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)