Logo

Programming-Idioms

  • PHP
  • Java

Idiom #46 Extract beginning of string (prefix)

Create the string t consisting of the 5 first characters of the string s.
Make sure that multibyte characters are properly handled.

String t = s.substring(0,5);

s must not be null.
$t = mb_substr($s, 0, 5, 'UTF-8');

Requires the non-default extension mbstring
T : String := S (1 .. 5);

New implementation...