#includevoid CheckString(const TDesC& aString, const TChar& aChar) { TPtrC ptr(aString); if (ptr.Locate(aChar) != KErrNotFound) { // aChar is found in aString } else { // aChar is not found in aString } } int main() { const TDesC string(_L("Hello, world!")); CheckString(string, 'w'); return 0; }
#includeThis example takes a string, a start position, and a substring length as input, creates a TPtrC object from the string, and uses the Mid method to extract a substring starting at the specified position and running for the specified length. The resulting substring is stored in a new TPtrC object. Package/Library: Epoc32.libvoid ExtractSubstring(const TDesC& aString, TInt aStartPos, TInt aLength) { TPtrC ptr(aString); if (ptr.Length() >= aStartPos + aLength) { TPtrC subPtr = ptr.Mid(aStartPos, aLength); // subPtr now contains the substring starting at aStartPos and running for aLength characters } else { // invalid start position or substring length } } int main() { const TDesC string(_L("Hello, world!")); ExtractSubstring(string, 7, 5); return 0; }