Left$, Right$, Mid$ ... Would this work??
m.r.b.
Posts: 36
Hello All...
I am not in front of my 'development PC' right now.
I'm trying to work out Left$,Right$ and Mid$ functions
Will this work?? If its right, it might be useful to someone...
Or is there a faster/better way embedded into spin..
[noparse][[/noparse]code]
PUB LeftStr(SourcreStringPtr,DestStringPointer,RhsChop)
{{
· @DestStringPointer = LEFT$(@SourcreStringPtr,RhsChop)····················
}}
· MidStr(SourcreStringPtr,DestStringPointer,0,RhsChop)
PUB RightStr(SourcreStringPtr,DestStringPointer,LhsChop)
{{
· @DestStringPointer = RIGHT$(@SourcreStringPtr,LhsChop)····················
}}
· MidStr(SourcreStringPtr,DestStringPointer,LhsChop,strsize(SourcreStringPtr))
PUB MidStr(SourcreStringPtr,DestStringPointer,LhsChop,RhsChop) | TempPointer
{{
· @DestStringPointer = MID$(@SourcreStringPtr,LhsChop,RhsChop)
· IE MID$("ABCDEFG",2,3) RETURNS "CD"····················
}}
· repeat TempPointer from (SourcreStringPtr+LhsChop) to (SourcreStringPtr+RhsChop)
···· byte[noparse][[/noparse]DestStringPointer++] := (byte[noparse][[/noparse]TempPointer])
· byte[noparse][[/noparse]DestStringPointer] := 0 'Add the zero terminator to the end of the string.
[noparse][[/noparse]code/]
Regards
M.R.B.
I am not in front of my 'development PC' right now.
I'm trying to work out Left$,Right$ and Mid$ functions
Will this work?? If its right, it might be useful to someone...
Or is there a faster/better way embedded into spin..
[noparse][[/noparse]code]
PUB LeftStr(SourcreStringPtr,DestStringPointer,RhsChop)
{{
· @DestStringPointer = LEFT$(@SourcreStringPtr,RhsChop)····················
}}
· MidStr(SourcreStringPtr,DestStringPointer,0,RhsChop)
PUB RightStr(SourcreStringPtr,DestStringPointer,LhsChop)
{{
· @DestStringPointer = RIGHT$(@SourcreStringPtr,LhsChop)····················
}}
· MidStr(SourcreStringPtr,DestStringPointer,LhsChop,strsize(SourcreStringPtr))
PUB MidStr(SourcreStringPtr,DestStringPointer,LhsChop,RhsChop) | TempPointer
{{
· @DestStringPointer = MID$(@SourcreStringPtr,LhsChop,RhsChop)
· IE MID$("ABCDEFG",2,3) RETURNS "CD"····················
}}
· repeat TempPointer from (SourcreStringPtr+LhsChop) to (SourcreStringPtr+RhsChop)
···· byte[noparse][[/noparse]DestStringPointer++] := (byte[noparse][[/noparse]TempPointer])
· byte[noparse][[/noparse]DestStringPointer] := 0 'Add the zero terminator to the end of the string.
[noparse][[/noparse]code/]
Regards
M.R.B.
Comments
I say minimally because the Basic versions have a lot of checking implied so that the copy stops at the end of either the source or the destination string and "illegal" start and end values are not allowed. In Spin, there's no maximum length associated with a byte array that can be referenced by such a function. You'd have to add it as an extra parameter or store it as part of the byte array, etc.
You might consider using the BYTEMOVE statement which would be faster. Have a look at it in the manual.