Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Apr 22, 1998

C++ equivilant of Basic MID$

Question:
I need to test for a certain char in a char array. For example, in BASIC I would have:
if mid$(string,1,1) = "`" then
 blah blah blah....

How would I do this in C/C++? Note: I'm still new to C++ :P Compiler == Turbo C++ 3.0(Dos)

Answer:
Normally, you could just use:

   if (string[0] == '`') ...
This assumes that string is a character array (or pointer to a character array) and is much more efficient than BASIC's Mid$ function. (Note that the index for the first character is 0 and not 1).

If you are using a string class, the syntax might be a little different, but all good string classes provide a syntax for accessing individual characters and it often looks the same as that for character arrays.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date