StringVar.s contra StringVar$

Just starting out? Need help? Post your questions and find answers here.
User avatar
micha-b
User
User
Posts: 18
Joined: Wed Mar 29, 2023 8:51 am
Location: Heidelberg
Contact:

StringVar.s contra StringVar$

Post by micha-b »

I know StringVar.s and StringVar$ are two different things - but what makes them different?
What's the deeper sense of having two different types for string variables and when to use which one?

Kind regards,

Micha B.
User avatar
STARGÅTE
Addict
Addict
Posts: 2235
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: StringVar.s contra StringVar$

Post by STARGÅTE »

In the background, these strings are from exactly the same type, performance etc.
But keep in mind that the $ is part of the variable name. So you can declare StringVar$ and StringVar.s as separate variables (but it is not recommended).
I think, the declaration with the $ is just a leftover from the good old Basic era, similar to Dim instead of NewArray for example.

I prefer to use only StringVar.s
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: StringVar.s contra StringVar$

Post by luis »

They are the same data type but two different variables.

I prefer to use StringVar$ because when I look at the source then I can spot strings easily, I never use .s if I can avoid it.
Sometimes I have to use StringVar.String when I want to pass a input-output string to a procedure and that to me is horrible enough to look at.
"Have you tried turning it off and on again ?"
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: StringVar.s contra StringVar$

Post by Little John »

Some people prefer the toilet paper to hang down the front, others prefer it to hang down the back. :)
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: StringVar.s contra StringVar$

Post by jacdelad »

Little John wrote: Sat Jul 01, 2023 12:02 pm Some people prefer the toilet paper to hang down the front, others prefer it to hang down the back. :)
Comparing parts of purebasic with toilet paper? You should prepare yourself for a shitstorm. :mrgreen:

I use both variants without any pattern. :twisted:
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: StringVar.s contra StringVar$

Post by infratec »

If you use $ at the end, you can avoid the word String in front to see that it is a string :wink:
Less typing, easier to read.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: StringVar.s contra StringVar$

Post by luis »

Religious wars started for a lot less.
I would prepare my flag with a $ on top of it but someone could misunderstand it.
"Have you tried turning it off and on again ?"
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: StringVar.s contra StringVar$

Post by infratec »

But you need .s in a structure if you use it for ExtractJsonStructure() because $ does not fit the name of the json key.

Else, .s and $ are usable vice versa.
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: StringVar.s contra StringVar$

Post by Mijikai »

.s is stylistically more consistant therefore $ should be rejected.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: StringVar.s contra StringVar$

Post by RASHAD »

I agree with luis
When I receive an error message Number expected instead of a string I catch where the error exist directly
But still no harm to have both
Egypt my love
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: StringVar.s contra StringVar$

Post by mk-soft »

infratec wrote: Sat Jul 01, 2023 12:50 pm If you use $ at the end, you can avoid the word String in front to see that it is a string :wink:
Less typing, easier to read.
But you have to press the shift key to get a "$". :mrgreen:

It is best not to mix

A dynamic string variable is a pointer to the characters of string
When a string is changed, the pointer can change, for example, if the memory space for the new string is too small.

To pass a string ByRef to a function, one must pass the pointer to the pointer of the string (Stupid text!).

Code: Select all


Global fixedString.s{16}
Global fixedString${16}
Global dynamicString.s
Global dynamicString$
Global structString.String

fixedString = "Hello "
fixedString$ = "World!"

dynamicString = fixedString + fixedString$
dynamicString$ = UCase(dynamicString)

Debug dynamicString
Debug dynamicString$

structString\s = dynamicString$

Procedure fcStringByRef(*refStr.String)
  *refStr\s = "*** " + *refStr\s + " ***"
EndProcedure

fcStringByRef(@structString)

Debug structString\s


Since number variables have a fixed size, this can pass the pointer to the number

Code: Select all


Global varInteger.i

Procedure add(*var.Integer, value = 1)
  *var\i + value
EndProcedure

varInteger = 10
Debug varInteger
add(@varInteger, 10)
Debug varInteger
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Mohawk70
Enthusiast
Enthusiast
Posts: 404
Joined: Thu May 11, 2006 1:04 am
Location: Florida, USA

Re: StringVar.s contra StringVar$

Post by Mohawk70 »

I use $ for protected/local scope & .s for global scope.
HP Z800 Workstation
CPU : Dual Xeon 5690 3.46GHz
RAM : 96GB RAM ( 8GB x 12 )
PSU : 1100W
GPU : NVIDIA RTX 3050 8GB
STORAGE : 9TB
(4) 2TB Seagate IronWolf Pro HDD
(1) 1TB Samsung 870 EVO SSD
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: StringVar.s contra StringVar$

Post by idle »

I alway just thought someone's having a bad day no need to swear$ @#$##
I prefer .s
User avatar
skywalk
Addict
Addict
Posts: 4220
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: StringVar.s contra StringVar$

Post by skywalk »

Whoa! A single character tells me string data type or not. What's not to like?

Next you .s people will demand we drop the * from all our *Pointers?!?

Never! :twisted:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
idle
Always Here
Always Here
Posts: 5915
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: StringVar.s contra StringVar$

Post by idle »

skywalk wrote: Sat Jul 01, 2023 10:02 pm Whoa! A single character tells me string data type or not. What's not to like?

Next you .s people will demand we drop the * from all our *Pointers?!?

Never! :twisted:
people have to use pointers 1st! :lol:

I'd prefer *foo.i or *str.s
Post Reply