Substring

Can anyone tell me what is syntax of (mid(theString, 1, 1)) in C/C++ ? (In console)
Another question, can anyone tell me where should I go (website) if I am the beginner of visual C++ (windows programming, just like VB).
ahchongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahchongAuthor Commented:
Edited text of question.
0
Jan LouwerensSoftware EngineerCommented:
if you are are using the string class, use:
substr(start, length)  // use 'string::npos' for length to go till end of string

string a = "hello world";
string b = a.substr(3, 5); // b = 'lo wo'
0
akalmaniCommented:
Hi !!
   I got the answer for CString mid but u wanted only the mid function i am not aware.

For VC++ there is a book called ->
1)No experience required
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Jan LouwerensSoftware EngineerCommented:
CString is a Microsoft MFC class, and is not a C/C++ standard class. string is a standard C++ class.
If you're using MFC, the CString class may make things easier for you. If not, the string class is your best choice.

if you are using standard null terminated strings (char *), then use the strncpy function:

char* strncpy(char* dest, char* src, length n)
0
V_BapatCommented:
You should ask only one question at a time as it makes it easy for answering as well as for you to accept the answer and grade the answer.

> Can anyone tell me what is syntax of (mid(theString, 1, 1)) in C/C++ ? (In console)
I think you have got answer from jlouwere.

> Another question, can anyone tell me where should I go (website) if I am the beginner of visual C++ (windows programming, just like VB).
The best site I can tell you is:
http://devcentral.iftech.com/learning/tutorials
where you will find everything: C, C++, VC++/MFC, VB, Java to name a few.

Vicky
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ahchongAuthor Commented:
jlouwere:
   string a = "hello world";
   string b = a.substr(3, 5); // b = 'lo wo'
thank your for your answer, but I can't use it...
I am using Borland c/c++ 3.0, but I still don't know how to use the substr... seem that my c/c++ 3.0 have no this function... (when I searched for my help file, it seem to be no this function at all ), then how can I do it (or could you write a complete script) ????
all your response will be appreciated, thanks !
0
ahchongAuthor Commented:
jlouwere:
   string a = "hello world";
   string b = a.substr(3, 5); // b = 'lo wo'
thank your for your answer, but I can't use it...
I am using Borland c/c++ 3.0, but I still don't know how to use the substr... seem that my c/c++ 3.0 have no this function... (when I searched for my help file, it seem to be no this function at all ), then how can I do it (or could you write a complete script) ????
all your response will be appreciated, thanks !
0
Jan LouwerensSoftware EngineerCommented:
the substr(...) function is a method of the class 'string'. it is not a global c function. To use the string class, make sure that you include the line:

#include <string>

at the top of your source file. This will allow you to use the string class

(How old is Borland 3.0? Does it contain the STL classes? string is one of the STL classes)
0
ahchongAuthor Commented:
By Using Visual C++ 5.0:
#include <iostream.h>
#include <string.h>
void main (void) {  
      cout << "Hello world".substr(3,5);      
}
This is the problem:
error C2228: left of '.substr' must have class/struct/union type
   How can I correct it ?
0
Jan LouwerensSoftware EngineerCommented:
#include <iostream>
#include <string>

void main (void) {    
   string msg = "Hello world";
   cout << msg.substr(3,5);
}
0
ahchongAuthor Commented:
sorry that I am the beginner of C language...
jlouwere :
from your source code..
#include <iostream>
#include <string>

void main (void) {    
   string msg = "Hello world";
   cout << msg.substr(3,5);
}

I can't run it ... it said the "string" got problem... how can I fix it ?
0
Jan LouwerensSoftware EngineerCommented:
what do you mean by "string got problem"?
can you print exactly what the error is?

Also, are you using C++ or only straight C? string is a class defined in the STL (Standard Template Library) for the C++ language.
0
ahchongAuthor Commented:
Now I am using vc++,
#include <iostream>
#include <string>

void main (void) {      
   "string" msg = "Hello world";
   cout^ << msg.substr(3,5);
}      |
      this string got problem....
0
Jan LouwerensSoftware EngineerCommented:
maybe try this for that line:

std::string msg = "Hello world";

DO you have the online docs that come with VC++? I think Mocrosoft has their own implementation of the STL, and that may be causing some kind of conflict.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.