SString vs. native String;

Share your advanced PureBasic knowledge/code with the community.
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

SString vs. native String;

Post by HanPBF »

I had the problem to distinct a boxed string from a native string and use it in parallel.

Now I found a somewhat solution.
Not a spectacular thing but at least stored here...

Code: Select all

EnableExplicit

#Namespace_Base   = 16
#Namespace_Native = 32
#Type_String          = 32

Structure SAny
	Namespace.w
	Type.w
EndStructure

Structure SString extends SAny
	Value.s
EndStructure


define S1.s = "  Test for a string 1" ; 2 spaces are important!!!

define *S2.SString = AllocateStructure(SString)
*S2\Namespace = #Namespace_Base
*S2\Type      = #Type_String
*S2\Value     = "Test for a string 2"


Procedure	 checkString(*S.SString)
	if *S\Namespace=32 and *S\Type=32
		debug mid(PeekS(*S), 3)	
	else
		Debug *S\Value
	endif
EndProcedure

checkString(@S1)
checkString(@"  test")
checkString(*S2)
That was my problem before: how to easily give static string and boxed string to the same function...
Now, the rule is: put two spaces at beginning and handling gets nearly the same.

And it does only work with unicode (or type/namespace must be .b).