Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't fall for the mid$ trap
#1
Intuitively you might think this would come back as "yes" answer:

a$ = "apples pears"
If Mid$(a$, 7) = " " Then
    Print "yes"
Else
    Print "no"
End If

Sorry it's a"no", but this is a "yes"

a$ = "apples pears"
If Asc(a$, 7) = 32 Then
    Print "yes"
Else
    Print "no"
End If

If it wasn't for the Wiki mentioning ASC is faster.  I am have been stuck a bit longer.  Reality is mid$ is used to move strings into or out of strings.  Not for testing a value.  Here is another tibit.  Mother tongue QB45 says yes "mid$" is wrong usage, "asc" is the way.  But "why is there always a but", maybe because everyone has one.  QB45 only gets the first ASC character in the string.  QB64pe allows a position of your choice for the asc value.  For all my "QB" life I only used mid$ for substitute or pull character(s) in a string.  Learn something new everyday.  How much do you want to bet, I will forget this lesson.

/flame shield on

Ok come at me.
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,272 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,309 08-14-2022, 11:48 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)