Link to home
Start Free TrialLog in
Avatar of krupini
krupini

asked on

How to add characters or strings to a string?

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!

ASKER CERTIFIED SOLUTION
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gillgates
gillgates

string add(string stringtoadd, int numberofadds)
{
    string temp = "";

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