Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about substr()

Status
Not open for further replies.

minifiredragon

Programmer
Jun 29, 2003
68
US
I have been doing some looking around on ways to read certain characters of a CString into different variables and found substr();. But when I impliment it, I get an error:

C2039: 'substr' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]

is there something I am doing wrong or can't it be used for a CString? Here is how I use it:

CString numtocheck = m_strcardcheck;
CString firstfour;
firstfour = m_strcardcheck.substr(0,4);

As you see I want the 1st four digits of the number entered. Some advice would be a great help, since you all have helped tremendously in the past.

Thanks!!

PS. I did search the forum here and found 2 threads on substrings but neither were of use.
 
The error desc says it all:
'substr' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'

CString firstfour = m_strcardcheck.Left(4);


/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
But I thought it took 2 numbers and not one?? Or is it not needed if you start in the beginning?
 
Sorry I pushed the submit button instead of preview post, so please ignore my above post. I see that u are using the left command, but what would I do when I wanted the get the rest of the string (after the 1st 4)? Isn't that was substr is used for?? I saw on MSDN that they use it. Now I am a bit lost.
 
>what would I do when I wanted the get the rest of the string

Some examples:

CString firstFour = m_strcardcheck.Left(4);
CString afterFirstFour = m_strcardcheck.Mid(4);
CString firstThreeAfterFirstFour = m_strcardcheck.Mid(4,3);
CString lastSeven = m_strcardcheck.Right(7);

>Isn't that was substr is used for
There are several ways to do the same thing. Or more specific: There are several ways to represent a string.

With CString comes Left, Right and Mid, (so I'd say it's appropriate to use them when dealing with CStrings).

substr is a std::string method, not a CString gizmo (although I can see that CString in .NET has stolen borrowed a lot of ideas from the std::string implementation).






/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
Interesting, where can I get more information on the availible functions of CString?? It took me a day to locate substr. I ran searches in google on CString functions, but they appear to be all std::string functions.

I would love to get a reference like MASM's programming codes where they have all the commands in there, and ya just look up what u need.
 
I see, thanks!! That explains why I didn't find anything, I only searched for CString, not CStringT.
 
>I see, thanks!!

No problem. Thanks for the star ;-)

>I only searched for CString, not CStringT

Actually, since I haven't looked into C++ in .NET myself I searched for &quot;StrTraitMFC&quot;. It seemed like a unique enough search-word that was part of your first posting
(and I haven't heard of such a thing in MFC versions I'm familiar with)

:)




/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top