Looking for help with string formatting objects
turbosupra
Posts: 1,088
Being used to C sharp, string formatting is killing me in spin
I found 2 string objects, but none of them include the type of formatting functions I'd like to do.
I'm used to foreach loops and string.Contains()/array.Contains(), so I have been trying to figure out a way to do something like this
Is there any interest in putting together an expanded string object?
Unfortunately I'm not very good at spin code, or I'd have written the ones I wanted and offered them to the forum.
I found 2 string objects, but none of them include the type of formatting functions I'd like to do.
I'm used to foreach loops and string.Contains()/array.Contains(), so I have been trying to figure out a way to do something like this
public removeChars(array unwantedArray) { foreach(byte in byteArray) { if unwantedArray.Contains(byte) { byteArray.Remove(byte) } } }
Is there any interest in putting together an expanded string object?
Unfortunately I'm not very good at spin code, or I'd have written the ones I wanted and offered them to the forum.
Comments
One is using two pointers one pointer (A) keeps track of of the array index while the other pointer (B) reads bytes. Both pointer start at the same location. When a wanted character is found both pointer increment. When an unwanted character is found the index pointer (A) stays in position and pointer B increments. If the next byte is wanted then that byte is copied to the location of the index pointer (A) and both pointer increment else B increments again. The process repeats until you reach the end, probably a zero terminator. Finnaly copy the zero term to A. This is destructive to the original array.
Another way is to read a byte and if it is wanted copy the byte to a known buffer and increment the buffer pointer. If the byte is unwanted, go to the next byte and validate. This is not destructive to the original array but takes more memory.
-Phil
Is there a way to accumulate some of the other string functions found in c sharp, to a spin method such as
EndsWith
IndexOf
IndexOfAny
LastIndexOf
LastIndexOfAny
Remove
Replace
StartsWith
ToCharArray
TrimEnd
TrimStart
http://code.google.com/p/spinneret-web-server/source/browse/#svn%2Ftrunk%2FWeb_Page_Demo%253Fstate%253Dclosed
turbosupra, the list of functions you posted should be pretty easy to code in Spin. Each function should take just a few lines to implement.
BTW, I believe the lookdown technique that Phil posted would only work with a fixed list of characters. If yiou want to handle a string of characters in unwantedArray you would need to write a Contains method, as follows.
Maybe we can all work together and get a cumulative string object, as they aren't so easy for me, but maybe one day. I will be trying your code shortly.
As for Mike G's code link, it's a little tricky to find, but this link should work
STREngine Download Link
The make_mask method could easily be made fancier, to include options like case-independence, for example.
-Phil