please dont rip this site

Learning to Program with the Cybiko Handheld Computer Using B2C

Chapter 17 : String Manipulation (Right/Mid)

The B2C language offers no way to assign one string to another:

dim a[32] as char
dim b[32] as char
:
a = b  'illegal operation

Instead there are 2 statements for copying strings. These are the Mid statement (used for copying the middle of one string to another) and the Right statement (used for copying the right side of a string). The Mid and Right statements takes the form:

Mid destination, source, start [, length]   'the length is optional
Right destination, source, length

For the Mid statement, the 'destination' is a dimensioned string where the result will be stored. The contents of the original string will be discarded. The 'source' is a dimensioned string that holds data to be copied to the destination. The 'start' is a numerical value (variable, constant, or expression) indicating the first character from the 'source' to copy (remember, in B2C we count starting at zero). The optional length indicates how many bytes to copy. If the length is omitted, or if it is larger than the number of characters in the source array, the entire source array is copied.

The Right statement has similar parameters. The destination is the dimensioned string to copy into, and the source is the string to copy from. The length parameter is required and indicates how many letters from the RIGHT of the source string to copy into the destination.

In our example program we will learn to speak pig latin. It is not perfect. Can you think of ways to improve it?

Example Program

DO THIS

Copy the file "c:\…\B2Cv5\tutorial\ch18.b2c" to "C:\…\B2Cv5\ch18.b2c". Then execute the command "build ch18.b2c" Download the ch18.app file to the cybiko
 
'ch 18
dim word[32] as char   ' the word to convert
dim ordway[32] as char ' the resultant word
dim len as int         ' the length of ordway
 
input "enter your word ", word  'input
mid ordway, word, 1             'copy the word but not the 1st char
 
len = 0
for i=0 to 31                   'get the ordway length so we can add 'ay'
    if ordway[i] = 0 and len = 0 then
      len = i
    end if
next
'print len
ordway[len] = word[0]    ' append the first letter of word to the end of ordway
ordway[len+1] = 97       ' append 'a'
ordway[len+2] = 121      ' append 'y'
ordway[len+3] = 0        ' null terminator, very important
 
print word, "=", ordway  ' print results
input word ' wait for Enter


file: /Techref/cybiko/b2c/ch17.htm, 3KB, , updated: 2008/6/13 16:08, local time: 2024/11/26 07:39,
TOP NEW HELP FIND: 
3.133.124.161:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.org/techref/cybiko/b2c/ch17.htm"> cybiko b2c ch17</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .