Question

So I have a string in small talk, the string comes across TCP/IP connection as '$100xxxxxxZZ' where the x's are numbers 0-9 or letters A - Z, and the ZZ is the checksum as calculated by the sender. With the string I need to calculate a checksum of '100xxxxxx' in order to verify this is the correct msg and checksum. SO I need to be able to remove the '$' and 'ZZ' off of '$100xxxxxxZZ'

I already know how to truncate the 'ZZ' off, here's my code as it stands:

ValidateMsg: replyWithCheckSum

|newMsg tempMsg|
"removes the 'ZZ' from '$100xxxxxxZZ'  "
tempMsg := replyWithCheckSum copyFrom: 2 to: (replyWithCheckSum size -2).

"CODE TO REMOVE THE '$' AND STORE INTO newMsg"

"compares the 'ZZ' to the checksum calculated from newMsg"
^(self calcCheckSum: newMsg) = (self getCheckSumFromReply: replyWithCheckSum)

TL;DR how do I remove the 1st character in a string in smalltalk for visualworks 2.5 (yes I know this is ancient)

Was it helpful?

Solution

You could try

myString allButFirst

(which, btw, would work on any collection)

OTHER TIPS

In normal VisualWorks you would use #allButFirst: (works much like the related methods: #allButLast:, #first: and #last:). These are all helper methods around #copyFrom:to:.

If these methods don't exist in 2.5 yet, i encourage you to simply port them because they make life a lot easier. They're implemented in SequencableCollection and thus apply to a lot more classes than just Strings.

If you don't want to port them, just stick with #copyFrom:to:

You can also take a different approach.

newMsg := tmpMsg copyWithout: $$.

This copies the string but excludes the all $ characters during the copy. It doesn't do what you asked but it does what you want. This method will work in VisualWorks 2.5.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top