View a printable version of the current page.
  Wiki > Symbian Developer Network Public Wiki > ... > Example source code > URL encoding
  URL encoding
Added by alie, last edited by Rodney De Gale on Feb 15, 2008  (view change)
Labels: 
(None)

HBufC* CUrlUtil::UrlEncodeL(TDesC& aUrl)
{
   _LIT(KFormatCode, "%%%02x");

   if (!aUrl.Length())
   {
      return NULL;
   }

   TBufC<100> dontEncode = _L("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!-_.()*;/?:@&=+$[]!\\'()~");

  // Alloc to the maximum size of URL if every char are encoded
   HBufC *encoded = HBufC::NewL(aUrl.Length() * 3);

   // Parse a the chars in the url
   for (TInt i=0; i<aUrl.Length(); i++)
   {
      TChar toFind = aUrl[i];
      if (KErrNotFound == dontEncode.Locate(toFind) )
      {
         // Char not found encode it.
         encoded->Des().AppendFormat(KFormatCode, toFind);
      }
      else
      {
         // char found just copy it
         encoded->Des().Append(toFind);
      }
   }

   // Reallocate to the real size of the encoded url.
   encoded->ReAllocL(encoded->Length());

   return encoded;
}

Or simply use EscapeUtils class from SDK

Interactive Services Terms & Conditions of use | Terms of use | Privacy policy | Media Center | Contact us | © 2008 Symbian