Sample code for 30+ languages & platforms
PHP

StringBuilder GetNth

Demonstrates the GetNth method.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\StringBuilder;

// The GetNth method is handy for getting parts from delimited strings.
// For example:

$sb = new StringBuilder();
$sb->Append('red,blue,"green,purple",,yellow');

$delimiterChar = ',';
$exceptDoubleQuoted = true;
$exceptEscaped = true;

// Prints "[red]"
echo '[', $sb->GetNth(0, $delimiterChar, $exceptDoubleQuoted, $exceptEscaped), "]\n";

// Prints "[blue]"
echo '[', $sb->GetNth(1, $delimiterChar, $exceptDoubleQuoted, $exceptEscaped), "]\n";

// Prints "[green,purple]"
echo '[', $sb->GetNth(2, $delimiterChar, $exceptDoubleQuoted, $exceptEscaped), "]\n";

// Prints "[]"
echo '[', $sb->GetNth(3, $delimiterChar, $exceptDoubleQuoted, $exceptEscaped), "]\n";

// Prints "[yellow]"
echo '[', $sb->GetNth(4, $delimiterChar, $exceptDoubleQuoted, $exceptEscaped), "]\n";

// Prints "[]"
echo '[', $sb->GetNth(5, $delimiterChar, $exceptDoubleQuoted, $exceptEscaped), "]\n";