Solved

How to add characters or strings to a string?

Posted on 2004-08-23
2
188 Views
Last Modified: 2010-04-15
string text = "";
string add = "badger";

I want some function so that 'text' would equal to "badgerbadgerbadgerbadger..." and so on. The 'add' would be inserted into 'text' a specified amount of times.

I have tried the 'Insert()' function, but it does not seem to work. Thanks!

0
Comment
Question by:krupini
2 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 80 total points
Comment Utility
for (i=0; i<n; i++) text=text+add;
0
 
LVL 3

Expert Comment

by:gillgates
Comment Utility
string add(string stringtoadd, int numberofadds)
{
    string temp = "";

    for(int i = 0; i<numberofadds; i++)
    {
          temp += stringtoadd;
    }
   
    return temp;
}        
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now