Function Main As String
' Show string manipulations

' THE EXAMPLE ILLUSTRATES THE USE OF:
'   Len
'   Spc
'   Instr
'   Left
'   Right
'   Mid



Dim s,s0,say,say1,dcr As String,i,j,k As Integer
Const title="SHOW STRING FUNCTIONS"

  s0="An Example Text"

  k=MBB_OK + MBI_INFORMATION
  dcr=Chr(13)+Chr(13)

  'Note the use of Chr to insert carriage return symbols (decimal code 13)
  say="Note that "+dcr

  'Show source string
  i=MessageBox(say+"original string s0 = "+dcr+"'"+s0+"'", title, k)

  'Apply Len,Spc to expand source string to 20 characters (with leading spaces)
  s=s0
  If Len(s0)<20 Then s=Spc(20-Len(s0)+1)+s0
  i=MessageBox(say+"Spc(20-Len(s0)+1)+s0 = "+dcr+"'"+s+"'", title, k)

  'Left
  s=Left(s0,2)
  i=MessageBox(say+"Left(s0,2) = "+dcr+"'"+s+"'", title, k)

  'Right
  s=Right(s0,4)
  i=MessageBox(say+"Right(s0,4) = "+dcr+"'"+s+"'", title, k)

  'Mid
  s=Mid(s0,4,7)
  i=MessageBox(say+"Mid(s0,4,7) = "+dcr+"'"+s+"'", title, k)

  'InStr
  s="Example"
  j=InStr(1,s0,s)
  If j>0 Then
    say1="' sits in  s0 at "+Str(j)+"-th position"
  Else
    say1="' not found  in  s0"
  End If
  i=MessageBox(say+"'"+s+say1, title, k)

  'InStr
  s="RealText"
  j=InStr(1,s0,s)
  If j>0 Then
    say1="' sits in  s0 at "+Str(j)+"-th position"
  Else
    say1="' not found  in  s0"
  End If
  i=MessageBox(say+"'"+s+say1, title, k)

  Main="Demo completed"
End Function