Visit Mozilla.org

nsACString:BeginReading

From MDC

« XPCOM API Reference

Contents

[edit] Summary

The BeginReading function returns a const pointer to the first element of the string's internal buffer.

 const char_type* BeginReading() const;

[edit] Remarks

The resulting character array is not necessarily null-terminated. The length of the array is determined by the result of the Length method.

[edit] Example Code

  // count the number of times a particular character appears in the string

  PRUint32 CountChar(const nsACString& str, char c)
  {
    const char* start = str.BeginReading();
    const char* end = str.EndReading();

    PRUint32 count = 0;
    while (start != end)
    {
      if (*start++ == c)
        ++count;
    }

    return count;
  }

[edit] See Also

Length, EndReading