Substring from a string
-
Hi all, I have string like this. First name: name I want to get the string after the ':'. What is the easiest way. I'm wired with my way, find the length, find the place where : sign include and stuck...
I appreciate your help all the time... Eranga :)
-
Hi all, I have string like this. First name: name I want to get the string after the ':'. What is the easiest way. I'm wired with my way, find the length, find the place where : sign include and stuck...
I appreciate your help all the time... Eranga :)
If you're using MFC, it'd be easily done with the
CString::Mid()
function:CString str = \_T("Name: Rajesh"); int iPos = str.Find(\_T(":"),0); AfxMessageBox(str.Mid(iPos+1));
Or, if you aren't using MFC, then perhaps this helps you:
TCHAR \*tch = new TCHAR(20); tch = \_T("Name:Rajesh"); while(tch++) { if(\*tch == ':') { ::MessageBox(NULL, (tch+1), \_T("Message"), MB\_ICONINFORMATION); break; } }delete tch;
Last modified: 15mins after originally posted --
Rajesh.
-
If you're using MFC, it'd be easily done with the
CString::Mid()
function:CString str = \_T("Name: Rajesh"); int iPos = str.Find(\_T(":"),0); AfxMessageBox(str.Mid(iPos+1));
Or, if you aren't using MFC, then perhaps this helps you:
TCHAR \*tch = new TCHAR(20); tch = \_T("Name:Rajesh"); while(tch++) { if(\*tch == ':') { ::MessageBox(NULL, (tch+1), \_T("Message"), MB\_ICONINFORMATION); break; } }delete tch;
Last modified: 15mins after originally posted --
Rajesh.
And what is the purpose of heap allocated memory?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
And what is the purpose of heap allocated memory?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeMy bad mood perhaps? Seriously, just typed it out fast, tried and pasted here. Shouldn't have been fragmenting the precious heap though. Will take care of this in the future, my lord. :)
-
Hi all, I have string like this. First name: name I want to get the string after the ':'. What is the easiest way. I'm wired with my way, find the length, find the place where : sign include and stuck...
I appreciate your help all the time... Eranga :)
-
My bad mood perhaps? Seriously, just typed it out fast, tried and pasted here. Shouldn't have been fragmenting the precious heap though. Will take care of this in the future, my lord. :)
Rajesh R Subramanian wrote:
my lord
Wasn't Dunn? :laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Rajesh R Subramanian wrote:
my lord
Wasn't Dunn? :laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPallini wrote:
Wasn't Dunn?
Opph korse he izz. :laugh:
-
CPallini wrote:
Wasn't Dunn?
Opph korse he izz. :laugh:
:laugh:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hi all, I have string like this. First name: name I want to get the string after the ':'. What is the easiest way. I'm wired with my way, find the length, find the place where : sign include and stuck...
I appreciate your help all the time... Eranga :)
This what I have done
string strPT("First name: name"); int strLength = strPT.length(); int indexOfCol = strPT.find(':'); string strMess = strPT.substr(indexOfCol + 2, (strLength - indexOfCol));
I appreciate your help all the time... Eranga :)
-
If CString is used, write
CString str;
str.Mid (str.Find (':'));If not using CString, write
char* pszName = strstr (variable, ":");
if (pszName != NULL)
{
pszName is valid pointer.
}Come online at:- jubinc@skype
Thanks, actually I'm trying this on standard C++ pal :)
I appreciate your help all the time... Eranga :)