Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

String Formatting

See String Interpolation. Here's a quick example:

Code Block
firstname = "First"
lastname = "Last"

print "Your name is $firstname $lastname."

print "Now is $(date.Now)."

ToString() method

To convert a class or a type to a string, call the ToString() method. Or if you are writing your own class you can define your own ToString() method to control how your class is printed.

Converting from int to string and back

Code Block
//string to int
val as int
val = int.Parse("1000")
print val

//string to double
pi as double
pi = double.Parse("3.14")
print pi

//int or double to string
s as string
s = val.ToString()
print s

//multiple values to one formatted string
astr as string
astr = "$val and $pi"
print astr

//date parsing
d as date
d = date.Parse("12/03/04")

Parsing and converting other types

See this tutorial on the Parse and Convert techniques, as well as date parsing.

String Comparisons

Code Block
//regular comparison
if "asdf" == "ASDF":
	print "asdf == ASDF"
	print "asdf != ASDF"

//case-insensitive comparison
if string.Compare("asdf", "ASDF", true) == 0:
	print "case-insensitively the same"

s = "Another String"

if s.StartsWith("Another"):
	print "starts with 'Another'"
if s.EndsWith("String"):
	print "ends with 'String'"

print "'String' starts at:", s.IndexOf("String")

print "The last t is at:", s.LastIndexOf("t")

//use built-in regex support to split a string
words = @/ /.Split(s) //split on whitespace (could use \s)
for word in words:
	print word

See the .NET reference on Basic String Operations for more information on string comparisons.