There are times when you want to use fixed-width characters when you don’t know or can’t control the font, or you want to mix with proportional-width easily. The Unicode character set has you covered.
The Unicode codes &uFF01-&uFF5E are fixed-width versions of the visible ASCII range, and conversion is easy. Simple apply the formula s.Asc + &hFF00 - 32 to get the code. For example:
var s as string = "A"
s = Chr( s.Asc + &hFF00 - 32 ) // A fixed-width "A"
The space is less obvious as it’s not in that range, but you can use &u3000 for a fixed-width space.
Yes, I’ve seen some of these chars in spam mails - they look like ordinary chars but are used to beat spam detection. Each is 3 bytes long in UTF8, so be aware.
Public Function ToFixedWidth(Extends s As String) As String
var chars() as string = s.Split( "" )
for i as integer = 0 to chars.LastIndex
var char as string = chars( i )
var code as integer = char.Asc
if code > 32 and code < 127 then
chars( i ) = Chr( code + &hFF00 - 32 )
end if
next
s = String.FromArray( chars, "" )
s = s.ReplaceAll( &u0020, &u3000 )
return s
End Function