Mid, Left & Right functions for Strings in Cerberus X

It’s beginning to be late night, but I want share these with you.

Many of you probably remember Mid, Left and Right functions for strings in basic programming languages.

  • Mid returns from given position x amount of chars
  • Left returns from left x amount of chars
  • Right returns from right x amount of chars

These are easy to implement in Cerberus X, since it has nice string slicing methods.

Implementation for Mid:

Method Mid:String(str:String, startPos:Int, howMany:Int)
        Return str[(startPos)..(startPos+howMany)] 

Implementation for Left:

Method Left:String(str:String, howMany:Int)
     Return str[0..howMany]

Implementation for Right:

Method Right:String(str:String, howMany:Int) 
     Return str[(str.Length()-howMany)..(str.Length())]

You can test these for example with print Mid(“This is String”,5,2).

That’s it for tonight..

%d bloggers like this: