[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

string question

Posted on 2004-10-14
1
Medium Priority
?
217 Views
Last Modified: 2010-04-01
I have strings with the following format

"ABSCD 1M" or "GSFDG 3M" or "TTTGF 30Y"

I'm using string class. The 7th character will always be a number. How do I change the strings to show
"ABSCD (1M)" or "GSFDG (3M)" or "TTTGF (30Y)"

Thanks
0
Comment
Question by:healingtao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 12309462
The idea would be to locate the blank, insert the bracket after it and then append another one to the end, e.g.

#include <string>
#include <iostream>
using namespace std;

string str = "ABSCD 1M";
int pos;

pos = str.find(" ");

if ( -1 == pos) { // not found

    // error
}

str.insert(pos + 1, "("); // insert bracket after blank
str.append(")"); // append other bracket

cout << str.c_str() << endl;

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question