Sample code for 30+ languages & platforms
Ruby

StringBuilder GetNth

Demonstrates the GetNth method.

Chilkat Ruby Downloads

Ruby
require 'chilkat'

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

sb = Chilkat::CkStringBuilder.new()
sb.Append("red,blue,\"green,purple\",,yellow")

delimiterChar = ","
exceptDoubleQuoted = true
exceptEscaped = true

# Prints "[red]"
print "[" + sb.getNth(0,delimiterChar,exceptDoubleQuoted,exceptEscaped) + "]" + "\n";

# Prints "[blue]"
print "[" + sb.getNth(1,delimiterChar,exceptDoubleQuoted,exceptEscaped) + "]" + "\n";

# Prints "[green,purple]"
print "[" + sb.getNth(2,delimiterChar,exceptDoubleQuoted,exceptEscaped) + "]" + "\n";

# Prints "[]"
print "[" + sb.getNth(3,delimiterChar,exceptDoubleQuoted,exceptEscaped) + "]" + "\n";

# Prints "[yellow]"
print "[" + sb.getNth(4,delimiterChar,exceptDoubleQuoted,exceptEscaped) + "]" + "\n";

# Prints "[]"
print "[" + sb.getNth(5,delimiterChar,exceptDoubleQuoted,exceptEscaped) + "]" + "\n";