Concatenate-UNCONCATENATE

General FreeBASIC programming questions.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Concatenate-UNCONCATENATE

Post by owen »

Dim As String a,b,c,d
a="hello"
b="world"
Print a 'hello
Print b 'world
c=a+b 'Concatenate
Print c 'helloworld
d=c-b 'UNCONCATENATE
Print d 'hello
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Concatenate-UNCONCATENATE

Post by BasicCoder2 »

Code: Select all

Dim As String a,b,c,d
a="hello"
b="world"
Print a
Print b
c = a & b
Print c
d = left(c,len(c)-len(b))
Print d
sleep
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Concatenate-UNCONCATENATE

Post by fxm »

Because of QBasic history, the "+" operator is also defined for strings (and not only for numeric values addition), but the good syntax for concatenation of strings is the "&" operator (as BasicCoder2 shows above).
None operator for the "unconcatenation" of strings exists.
Last edited by fxm on Sep 23, 2017 13:37, edited 1 time in total.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: Concatenate-UNCONCATENATE

Post by owen »

Operator + (String Concatenation)
Operator - (String UnConcatenation)?
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Re: Concatenate-UNCONCATENATE

Post by angros47 »

In what language? Also, what is "unconcatenation" supposed to be?
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: Concatenate-UNCONCATENATE

Post by owen »

I am thinking about adding strings to fbcadcam-macro and oh boy is is a lot of work.
Until I started looking into this idea this morning, I never knew the difference between the string operators + and &.
It really goes to show how much thought went into creating the freebasic compiler.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: Concatenate-UNCONCATENATE

Post by owen »

What is the opposite operator for &
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Concatenate-UNCONCATENATE

Post by fxm »

"Unconcatenation" could be defined as the suppression of a sub-string inside another string (if sub-string exists)!
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: Concatenate-UNCONCATENATE

Post by owen »

After all these years I only know a fraction of freebasic's features. So I have a lot to learn.
I'm thinking the solution is an operator overload?
But because I am unfamiliar with what it means to overload an operator, perhaps I'll learn a bit more today.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: Concatenate-UNCONCATENATE

Post by owen »

In what language? Also, what is "unconcatenation" supposed to be?
The only stuff I could find online was talks specific to excel.

So It's still undefined.

As basichCoder2 defined it.
Or perhaps
"Hello World. Welcome to the Freebasic World"
UnConcatenated could be
"Hello . Welcome to the Freebasic "
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Concatenate-UNCONCATENATE

Post by fxm »

fxm wrote:"Unconcatenation" could be defined as the suppression of a sub-string inside another string (if sub-string exists)!

Code: Select all

#define unconcatenate(str, substr) Iif(Instr(str, substr), _
                                       Left(str, Instr(str, substr) - 1) & Mid(str, Instr(str, substr) + Len(substr)), _
                                       str)

Dim As String a, b, c, d, e
a= "hello"
b= "world"
c= "!"
Print a
Print b
Print c
d = a & b & c
Print d
e = unconcatenate(d, b)
Print e

Sleep
[edit]
- macro corrected on dodicat's remark below.
Last edited by fxm on Sep 23, 2017 14:52, edited 1 time in total.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: Concatenate-UNCONCATENATE

Post by owen »

yup it could be like that.
i was thinking it would be part of the compiler in the future using operators - and whatever the opposite of & is.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Concatenate-UNCONCATENATE

Post by dodicat »

hellow! is left, shouldn't it be hello!
(One place to left to include)

Code: Select all

#define unconcatenate(str, substr) Iif(Instr(str, substr), _
                                       Left(str, Instr(str, substr)-1) & Mid(str, Instr(str, substr) + Len(substr)), _
                                       str) 
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Concatenate-UNCONCATENATE

Post by fxm »

Thanks.
I corrected my above post.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Concatenate-UNCONCATENATE

Post by Josep Roca »

> Also, what is "unconcatenation" supposed to be?

This is usually called Remove.
Post Reply