Mid$
ReturnString$ = Mid$(SourceString$, Position, [Length=1])
 
Parameters:

    SourceString$ = The string you want to copy characters from
    Position = The first character (from the left) of where to start grabbing characters
    [Length=1] = The optional number of characters to grab, defaults to 1
Returns:

    ReturnString$
 

      The Mid$() function allows us to copy single character or run of characters from a source string to another string. The characters are copied in a left to right order, starting at the position parameter and ending at Position + Length.

      It's important to understand that MID$ does not remove the characters from the Source String, it just copies the selection of characters from the source string into a new string result.




FACTS:


      * If either the character position or copy length are outside the source strings length, the returned string fragment will be clipped to length of the source string.

      * The Mid$() function always returns a string. So if you want to read the strings ASCII values directly you should use MID() function.





Mini Tutorial:


  
  Number$="1234567890"
  Print Mid$(Number$,5,2)
  Print Number$
  Sync
  WaitKey
  


      In this example, the MID$ function will copy two characters from the string number$ starting at character five (from the left hand side). So it will output the characters 56 to the display.

      This example would output

  
  56
  1234567890
  


 
Example Source: Download This Example
; ================================
; MID$ EXAMPLE
; ================================
  
; Create a String Variable called "SourceString$" and place the text "<---Play Basic-->"
; within it.
  SourceString$= "<---Play Basic--->"
  
; Grab the 10 characters from SourceString$ stating at charcter 5 using Mid$(), then
; place those Characters into the variable Grab$
  
  Grab$=Mid$(SourceString$,5,10)
  
; Display the SourceString$ variable
  Print SourceString$
  
; Display the Grab$ variable..
  Print Grab$
  
; Show Us the Screen and Wait for Key Input before ending
  Sync
  WaitKey
  
  
 
Related Info: Left$ | Mid | Right$ | SplitToArray | Trim$ | TrimLEft$ | TrimRight$ :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com