How to typecast from integer to string and vice versa?
| Sun, 2005-04-10 17:51 | |
|
Hi!
I´m very new to Symbian and I need to know how to typecast variables from integers to strings and vice versa? For example: I have a TInt variable and I need to typecast this variable to TDesC. Can I do that? Are there other options? Can I use the itoa and atoi functions from C-language? |
|






Forum posts: 169
// TDesC& aStr ...
...
TInt aValue;
TLex(aStr).Val(aValue);
return aValue;
+++++++++++++++++ and Vice Versa:
// aIndex is an Integer...
HBufC8 *iMyBufNumber = HBufC8::NewLC(255);
TPtr8 bufNumberPtr(iMyBufNumber->Des());
bufNumberPtr.AppendNum(aIndex);
I hope it helps
Forum posts: 19
// TDesC& aStr ...
...
TInt aValue;
TLex(aStr).Val(aValue);
return aValue;
+++++++++++++++++ and Vice Versa:
// aIndex is an Integer...
HBufC8 *iMyBufNumber = HBufC8::NewLC(255);
TPtr8 bufNumberPtr(iMyBufNumber->Des());
bufNumberPtr.AppendNum(aIndex);
I hope it helps
Thanks! I haven´t tried yet, because I want to ask this question first.
Do i have to reallocate the memory used by the iMyBufNumber-variable after the typecast? If I have to how do I do that?
And other question too: why is 255 send as a parameter to NewLC?
Forum posts: 19
TKeyResponse CTestAppAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
HBufC8 *iMyBufNumber = HBufC8::NewLC(255);
TPtr8 bufNumberPtr(iMyBufNumber->Des());
bufNumberPtr.AppendNum(aKeyEvent.iScanCode);
}
What went wrong?
Forum posts: 13
//Integer to String;
TBuf <20> yourString;
TInt yourInteger;
yourString.Num(yourInteger);
Forum posts: 39
TKeyResponse CTestAppAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
HBufC8 *iMyBufNumber = HBufC8::NewLC(255);
TPtr8 bufNumberPtr(iMyBufNumber->Des());
bufNumberPtr.AppendNum(aKeyEvent.iScanCode);
}
What went wrong?
When you call "LC" function you should in the same function call CleanupStack::Pop (or PopAndDestroy).
Actualy bofore asking better to write what exact error occurs