Archived:Using CFindItemEngine to parse items from text
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Article Metadata
Contents |
Overview
This code snippet demonstrates how to use CFindItemEngine to parse different kinds of items, such as phone numbers, e-mail addresses, or URI addresses, from a given text. The type of the item is given to CFindItemEngine as a parameter when the object is constructed and also several types of items can be searched:
// Parse e-mail addresses from text
CFindItemEngine* searchEngine = CFindItemEngine::NewL(text,
CFindItemEngine::EFindItemSearchMailAddressBin);
// Parse URLs from text
CFindItemEngine* searchEngine = CFindItemEngine::NewL(text,
CFindItemEngine::EFindItemSearchURLBin);
// Parse URLs and phone numbers from text
CFindItemEngine* searchEngine = CFindItemEngine::NewL(text,
(CFindItemEngine::TFindItemSearchCase)
(CFindItemEngine::EFindItemSearchURLBin |
CFindItemEngine::EFindItemSearchPhoneNumberBin));
This snippet can be self-signed.
MMP file
The following libraries are required:
LIBRARY CommonEngine.lib
Source file
TBuf<256> text = _L("E-mail: foo.bar@invalid.com, Tel: 0700 468833, Www: http://www.testsite.net/.");
// Create an instance of CFindItemEngine to find every e-mail address from the text above
CFindItemEngine* searchEngine = CFindItemEngine::NewL(text,
CFindItemEngine::EFindItemSearchMailAddressBin);
// Retrieve the number of items
TInt count = searchEngine->ItemCount();
// Get currently selected item to the item variable
CFindItemEngine::SFoundItem item;
searchEngine->Item(item);
// Display every item
for (TInt i = 0; i < count; i++)
{
TPtrC result = text.Mid(item.iStartPos, item.iLength);
CAknInformationNote* note = new (ELeave)CAknInformationNote(ETrue);
note->ExecuteLD(result);
// Get the next item to the item variable
searchEngine->NextItem(item);
}
delete searchEngine;
Postconditions
Every e-mail address from the specific text is displayed on the screen.


(no comments yet)