Active Forums => QB64 Discussion => Topic started by: Dimster on February 18, 2021, 03:41:47 pm
Title: On Concatenation
Post by: Dimster on February 18, 2021, 03:41:47 pm
Concatenation only works by addition, there is no subtraction aspect to it. You can't for example have
A$ = "The Quick Brown Fox Jumped over the lazy dog" B$ ="clever cat" C$="Brown Fox" New$=A$ - C$ + B$
with the New$ is now reading "The Quick clever cat Jumped over the lazy dog"
Title: Re: On Concatenation
Post by: FellippeHeitor on February 18, 2021, 03:51:49 pm
You will have to manipulate your string with more detail/a bit more work than that.
- LEFT$ returns the specified amount of bytes from the left of a string: PRINT LEFT$("Hello, world!", 5) 'outputs Hello - RIGHT$ returns the specified amount of bytes from the right of a string: PRINT RIGHT$("Hello, world!", 5) 'outputs orld! - MID$ returns a portion from the middle of a string: PRINT MID$("Hello, world!", 8, 5) 'outputs world - MID$ can also return from a position in a string until the end if you don't specify length: PRINT MID$("Hello, world!", 8) 'outputs world! - INSTR allows you to find a substring inside a string: PRINT INSTR("Hello, world!", "w") 'outputs 8, since w is found at the 8th character in that string. - _INSTRREV does the same as INSTR, but starts looking from the end of the string to the first byte.
Check the example in these wiki pages: - http://www.qb64.org/wiki/MID$_(statement) (http://www.qb64.org/wiki/MID$_(statement)) - http://www.qb64.org/wiki/INSTR
Title: Re: On Concatenation
Post by: Dimster on February 18, 2021, 04:32:24 pm
Thanks Fell.
So if i convert a Scientific Notational value to a string ( ie A = .87659003E-02, A$ = STR$(A)) and I want to search for "E-02" is that the INSTR function that I would use? Result = INSTR(A$,"E-02")
When I run that code I get zero. The RIGHT$(A$,4) actually comes up with "E-03".
I'm a little stumped on it, brain has ceased.
Title: Re: On Concatenation
Post by: SMcNeill on February 18, 2021, 04:57:07 pm
Title: Re: On Concatenation
Post by: Dimster on February 18, 2021, 05:21:30 pm
That explains it - thanks guys -
Title: Re: On Concatenation
Post by: SMcNeill on February 18, 2021, 05:25:15 pm
Pete's right. (For once! OMG!!)
The reason why you can't find "E-02" in your search with INSTR is simply because A automatically converts to proper scientific notation. What you might want here, is something a little more flexible to simply look for the "E" or "D" in your string, like so:
Note that I've got 3 different functions here for SINGLE, DOUBLE, and _FLOAT values. This is because they store the same value much differently in memory. What might be 9.2E4 in single might simply be 92000 in double, or float.... You'll want your variable types to match to get the proper results back for you.
Title: Re: On Concatenation
Post by: Pete on February 18, 2021, 05:56:41 pm
"For once" as in that's where you end up with when you loop past infinity... twice!