Extract string from CString
-
is this useful,
CString sTemp = _T("Tag-10,OnOff-19,Switch-5,Lbl-10,Signal-22,trip-1");
int pos = sTemp.Find(_T("Lbl")) + 3;
CString resToken;
resToken = sTemp.Tokenize(_T("- ,"),pos);
if (resToken != "")
{
int num = _ttoi(resToken);
};That goes against OP title. :-D
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.
[my articles]modified on Tuesday, February 05, 2008 8:41:55 AM
-
That goes against OP title. :-D
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.
[my articles]modified on Tuesday, February 05, 2008 8:41:55 AM
may be more, but i think it covers what it needed:confused:
-
That goes against OP title. :-D
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.
[my articles]modified on Tuesday, February 05, 2008 8:41:55 AM
What? No solutions that use GetBuffer()?? I am shocked and appalled. :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
What? No solutions that use GetBuffer()?? I am shocked and appalled. :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
Only for you, to keep horror alive
strok(sTemp.GetBuffer(), "Lbl-");
:-D
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.
[my articles] -
Only for you, to keep horror alive
strok(sTemp.GetBuffer(), "Lbl-");
:-D
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.
[my articles]Ahhh yes - the world is balanced again. And bonus points for using the little-known strok() function hehe
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I have to extract a few character from CString. My CString is like this... Here i have to get the number of Lbl..I mean 10. My code is CString sTemp = {"Tag-10,OnOff-19,Switch-5,Lbl-10,Signal-22,trip-1"}; int pos = sTemp.Find("Lbl-"); Here i get the pos value as 25,then i want to get the character after Lbl- (ie) 10. How can i get ?Pls help me.
Anu
Use
CString::Mid()
, as NishantB++ already said to you.CString str = _T("Tag-10,OnOff-19,Switch-5,Lbl-10,Signal-22,trip-1");
AfxMessageBox(str.Mid(str.Find(_T("Lbl-"))+4,2));//4 and 2 may vary! Depends on your string.Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
Use
CString::Mid()
, as NishantB++ already said to you.CString str = _T("Tag-10,OnOff-19,Switch-5,Lbl-10,Signal-22,trip-1");
AfxMessageBox(str.Mid(str.Find(_T("Lbl-"))+4,2));//4 and 2 may vary! Depends on your string.Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
Rajesh R Subramanian wrote:
4 and 2 may vary!
I agree with 4 as he knows and is going to search using that string but if he knows 2 that means he already has the string with him and question is to find that string.
Anu_Bala wrote:
Here i have to get the number of Lbl..I mean 10.
-
Rajesh R Subramanian wrote:
4 and 2 may vary!
I agree with 4 as he knows and is going to search using that string but if he knows 2 that means he already has the string with him and question is to find that string.
Anu_Bala wrote:
Here i have to get the number of Lbl..I mean 10.
Apparently, you did not read the entire comment, did you? It's also mentioned "Depends on your string".
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
Apparently, you did not read the entire comment, did you? It's also mentioned "Depends on your string".
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
then the solution is if he want to find the number of Lbl, when it is 100, he want to build again :omg:
Rajesh R Subramanian wrote:
"Depends on your string".
Depends on the string, lbl10.exe, lbl110.exe ...
-
then the solution is if he want to find the number of Lbl, when it is 100, he want to build again :omg:
Rajesh R Subramanian wrote:
"Depends on your string".
Depends on the string, lbl10.exe, lbl110.exe ...
My mentioning "Depends on your string" states that he'd have to modify the code accordingly if the parameters change, so that it works always without having to rebuild. I thought it was pretty clear and anyone who fails to understand is just plainly dumb.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
My mentioning "Depends on your string" states that he'd have to modify the code accordingly if the parameters change, so that it works always without having to rebuild. I thought it was pretty clear and anyone who fails to understand is just plainly dumb.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
Rajesh R Subramanian wrote:
to modify the code accordingly if the parameters change
that is 2 to 3 when lbl is 100 that means he knows the length of string without the string i got. lbl10.exe no rebuild , lbl-100.exe no rebuild ... thanks :-D recalling ur mentioning of "Depends on your string"
Rajesh R Subramanian wrote:
//4 and 2 may vary! Depends on your string.
Rajesh R Subramanian wrote:
plainly dumb.
:omg: if he is such a person, i think he never post this, don't u even think, he is in need of this plain dumb solution of counting exercise, as he has NiShantB++ post already.
modified on Wednesday, February 06, 2008 11:30:57 PM