delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/03/02:18:02

From: Weiqi Gao <weiqigao AT a DOT crl DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help with strings MID$?
Date: Thu, 28 Aug 1997 19:00:44 -0500
Organization: Spectrum Healthcare Services
Lines: 36
Message-ID: <3406112C.4C82A8B@a.crl.com>
References: <01bcb3ea$4e6e4560$6889d2cd AT inventor DOT worldchat DOT com>
NNTP-Posting-Host: a116021.stl1.as.crl.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Vincent Collura wrote:
> 
> Hello,
> 
> I am new to C++ and am trying to convert a
> old QuickBasic utiltiy I wrote into C++.  It
> compiles fine except I still cant figure how
> to convert this Basic statement
> 
> tally(item) = MID$(touch$, 2, 5) + MID$(touch$, 41, 12) + MID$(touch$, 73,
> 7)
> 
> Into c++,  For those who dont know, mid$ returns the
> n'th character to the nth number.
> 
> What is the C++ function to do this?  I have
> tried StrnCat but the problem with this is you
> cant specificy a starting location.

One way of doing it is to use the GNU C++ class library libgpp.a's
String class.  The String class has a member function called at().  Your
BASIC code could be translated to:

String touch, tally;
tally = touch.at(2,5) + touch.at(4,12) + touch.at(73,7);

Look up the GNU C++ class library info file: "info libgpp String".

You might also want to check out the third edition of The C++ Language,
which describes the standard C++ library.  (I haven't checked, but) I
imagine there would be an ANSI C++ String class that has a member
function that does exactly what the String::at() function does.

--
Weiqi Gao
weiqigao AT a DOT crl DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019