Trimming whitespace in Dart strings from beginning or end

dart

Solution

There are no specific methods for trimming only leading or trailing whitespace. But it is quite easy to implement them:

/// trims leading whitespace
String ltrim(String str) {
  return str.replaceFirst(new RegExp(r"^\s+"), "");
}

/// trims trailing whitespace
String rtrim(String str) {
  return str.replaceFirst(new RegExp(r"\s+$"), "");
}

Problem

I am very new to Dart and am trying to get some sense of the basic libraries. For strings, there is a trim() function provided. This is good, but are there no obvious ways to trim whitespace only at the beginning or only at the end of a string? I cannot find them.Thank you.

Original source