String length

For finished programs
Post Reply
User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

String length

Post by kibernetik » Mon Sep 09, 2019 9:48 am

Example of text processing:

Code: Select all

dim b() t() = "abc","J̲o̲s̲é̲","møøse","𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
optionbase 1

print "We have"; (sizeof t); "words:"
for i = 1 to sizeof t
  if i>1 then print ", ";
  print t(i);
next
print : print

for i = 1 to sizeof t
  word = t(i)
  print "Word """; word; """ contains:"

  print (strlen word); "characters: ";
  for j = 1 to strlen word
    if j>1 then print ", ";
    print strmid (word, j, 1);
  next
  print

  b = strbytes word
  print (sizeof b); "bytes: ";
  for j = 1 to sizeof b
    if j>1 then print ", ";
    print (strtext b(j) "##");
  next
  print : print
next
Output:

Code: Select all

We have 4 words:
abc, J̲o̲s̲é̲, møøse, 𝔘𝔫𝔦𝔠𝔬𝔡𝔢

Word "abc" contains:
 3 characters: a, b, c
 3 bytes: 61, 62, 63

Word "J̲o̲s̲é̲" contains:
 4 characters: J̲, o̲, s̲, é̲
 13 bytes: 4A, CC, B2, 6F, CC, B2, 73, CC, B2, C3, A9, CC, B2

Word "møøse" contains:
 5 characters: m, ø, ø, s, e
 7 bytes: 6D, C3, B8, C3, B8, 73, 65

Word "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" contains:
 7 characters: 𝔘, 𝔫, 𝔦, 𝔠, 𝔬, 𝔡, 𝔢
 28 bytes: F0, 9D, 94, 98, F0, 9D, 94, AB, F0, 9D, 94, A6, F0, 9D, 94, A0, F0, 9D, 94, AC, F0, 9D, 94, A1, F0, 9D, 94, A2

User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: String length

Post by Dutchman » Tue Sep 10, 2019 8:08 am

Very educational about various types of characters. It was a long way from the DOS character set. :D
I have added a nutritious example. :lol:

Code: Select all

dim b() t() = "abc","J̲o̲s̲é̲","møøse","𝔘𝔫𝔦𝔠𝔬𝔡𝔢","🍎🍊🍋🍇"
optionbase 1

print "We have"; (sizeof t); "words:"
for i = 1 to sizeof t
  if i>1 then print ", ";
  print t(i);
next
print : print

for i = 1 to sizeof t
  word = t(i)
  print "Word """; word; """ contains:"

  print (strlen word); "characters: ";
  for j = 1 to strlen word
    if j>1 then print ", ";
    print strmid (word, j, 1);
  next
  print

  b = strbytes word
  print (sizeof b); "bytes: ";
  for j = 1 to sizeof b
    if j>1 then print ", ";
    print (strtext b(j) "##");
  next
  print : print
next
It is still a long way to go

Post Reply