Module Strutil


module Strutil: sig  end
String-related utilities.

This module provides various helpful utilities for dealing with strings.
Author(s): Copyright (C) 2004 John Goerzen




Whitespace removal
These functions are designed to remove extra whitespace from the start and end of strings. For the purposes of these functions, whitespace characters are defined as space, tab, carriage return, and line feed.

val strip : string -> string
Removes any whitespace characters that are present at the start or end of a string. Does not alter the internal contents of a string. If no whitespace characters are present at the start or end of a string, returns the original string unmodified. Safe to use on any string.

Note that this may differ from some other similar functions from other authors in that:

1. If multiple whitespace characters are present all in a row, they are all removed;

2. If no whitespace characters are present, nothing is done.

val lstrip : string -> string
Same as strip, but applies only to the left side of the string.
val rstrip : string -> string
Same as strip, but applies only to the right side of the string.


Conversions


val split : string -> string -> string list
Splits a string into multiple component strings.

Similar to Str.split_delim.

Example:


# split ":" ":jgoerzen::foo:bar:";;
  string list = [""; "jgoerzen"; ""; "foo"; "bar"; ""] 


delim : A string giving the delimiter
s : The string to split
val split_ws : string -> string list
Splits a string deliminted by whitespace into multiple component strings. Leading or trailing whitespace is ignored.
val join : string -> string list -> string
Makes one output string from the given string list by inserting the delim between each element. An alias for String.concat.
Returns A list of strings. Each item in the list is one that as separated by delim. The delim itself will never appear in the list. Empty strings may be in the list of one instance of delim immediately followed by another, or if delim occured at the beginning or end of a string.
val string_of_char : char -> string
Given a char, returns a one-character string composed of that character.

For instance, (string_of_char 'c') would produce "c".