Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't fall for the mid$ trap
#2
One thing of note -- this is the incorrect usage of MID$ for what you want to do:

a$ = "apples pears"
If Mid$(a$, 7) = " " Then


Notice that you're not telling it how many spaces you want from that string, so what you're basically saying is:
Go to the middle of the string, start at the 7th position, and return the rest of the string.
Mid$(a$, 7) = " pears"

What you actually wanted here was this usage:

If Mid$(a$, 7, 1) = " " Then

Notice that you're now telling it how many spaces you want from that string, so what you're basically saying is:
Go to the middle of the string, start at the 7th position, and return one character from the string.

Missed parameter = missed result.  Wink




That said; use the ASC version anyway, when you ever can.  It's much faster.  String comparison and manipulation is rather slow, but we do numeric ASCII compares quite effiicently.
Reply


Messages In This Thread
Don't fall for the mid$ trap - by doppler - 10-12-2025, 12:58 PM
RE: Don't fall for the mid$ trap - by SMcNeill - 10-12-2025, 01:18 PM
RE: Don't fall for the mid$ trap - by doppler - 10-12-2025, 01:32 PM
RE: Don't fall for the mid$ trap - by SMcNeill - 10-12-2025, 01:36 PM
RE: Don't fall for the mid$ trap - by bplus - 10-14-2025, 06:52 PM
RE: Don't fall for the mid$ trap - by Pete - 10-16-2025, 03:42 AM
RE: Don't fall for the mid$ trap - by dano - 10-16-2025, 10:45 AM
RE: Don't fall for the mid$ trap - by Pete - 10-16-2025, 09:12 PM
RE: Don't fall for the mid$ trap - by doppler - 10-18-2025, 12:47 AM
RE: Don't fall for the mid$ trap - by Pete - 10-19-2025, 08:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Don't let INKEY$ byte you in the ASCII Pete 1 165 02-01-2026, 10:44 PM
Last Post: PhilOfPerth
Question using $color:32 colour names mid-program? hskakw 2 207 01-14-2026, 09:30 AM
Last Post: hskakw
  Don't look now developers, but you've got a pat on your back! Pete 7 1,271 12-15-2024, 09:59 AM
Last Post: TempodiBasic
  "Well I don't give a damn about my bad reputation." TDarcos 16 3,522 09-13-2022, 12:32 AM
Last Post: Kernelpanic
  Don't make me REPETEND myself... Pete 23 4,308 08-14-2022, 11:48 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)