The unicode package has the MaxASCII constant for this purpose.
On Wednesday, June 11, 2014 10:49:23 AM UTC-4, mkb wrote:The unicode package has the MaxASCII constant for this purpose.
I knew it was there somewhere.
I answered too quickly, you should probably check for null bytes as well.
The OP asked for an IsASCII function, not an IsBinary function; _everything_ below 0x80 is ASCII, without exception. You might be thinking of IsPrintableASCII, which is not the same thing.
import "code.google.com/p/go.exp/utf8string"
Hope this is helpful.
Roger
On Wednesday, June 11, 2014 10:33:50 AM UTC-4, Ken MacDonald wrote:Hi,Looking for a function that will tell me if a string is entirely valid ASCII. One field in our input has to be checked, I verify the other fields for being valid UTF-8 which has a nice function available.Ken
--
func isASCII(s string) bool {for _, c := range s {if c > 127 {return false}}return true}