Overview

String Ops

Common string manipulation tasks

Source Code

<?pas
// Common string manipulation tasks

var rawText := '  Pascal,Scripting,Web  ';

PrintLn('<b>Original:</b> "' + rawText + '"');

// Trimming (no parentheses needed)
var trimmed := rawText.Trim;
PrintLn('<b>Trimmed:</b> "' + trimmed + '"');

// Splitting
var parts := trimmed.Split(',');
PrintLn('<b>Split parts:</b>');
PrintLn('<ul>');
for var s in parts do
  PrintLn('<li>' + s + '</li>');
PrintLn('</ul>');

// Replacing
var replaced := trimmed.Replace('Pascal', 'DWScript');
PrintLn('<b>Replaced:</b> "' + replaced + '"');

// Substrings and Deletion
var s := '123456789';
PrintLn('<b>Substring (2,3):</b> ' + s.Copy(2, 3)); // 234
PrintLn('<b>Substring (5+):</b> ' + s.Copy(5));     // 56789
PrintLn('<b>Delete Left (3):</b> ' + s.DeleteLeft(3));   // 456789
PrintLn('<b>Delete Right (3):</b> ' + s.DeleteRight(3)); // 123456

// Formatting
var formatted := Format(
  'Item: %s, Count: %d, Price: %.2f',
  [ 'Apple', 5, 1.25 ]
);
PrintLn('<b>Formatted:</b> ' + formatted);
?>

Result

<b>Original:</b> "  Pascal,Scripting,Web  "
<b>Trimmed:</b> "Pascal,Scripting,Web"
<b>Split parts:</b>
<ul>
<li>Pascal</li>
<li>Scripting</li>
<li>Web</li>
</ul>
<b>Replaced:</b> "DWScript,Scripting,Web"
<b>Substring (2,3):</b> 234
<b>Substring (5+):</b> 56789
<b>Delete Left (3):</b> 456789
<b>Delete Right (3):</b> 123456
<b>Formatted:</b> Item: Apple, Count: 5, Price: 1.25
On this page