473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Create string of repeated char

This is not really a C# question, but I'm not sure which is the best
group to post it. Please, point me to the right one.

What's the best way to create a string from a repeated char? For
instance, I pass char = "*" and size = 5, and get a string = "*****".

I could write a function to loop size times and append to a
StringBuilder, but maybe there is something ready in the framework.

Thanks.

--
Erick Sasse
Feb 1 '06 #1
3 2240
"Erick Sasse" <es****@newsgroups.nospam> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
This is not really a C# question, but I'm not sure which is the best
group to post it. Please, point me to the right one.

What's the best way to create a string from a repeated char? For
instance, I pass char = "*" and size = 5, and get a string = "*****".

I could write a function to loop size times and append to a
StringBuilder, but maybe there is something ready in the framework.


One of the constructors for string takes a character and an int as parameters.
It does what you want.

Bill
Feb 1 '06 #2
String s;
s.PadRight(5, '*');

"Erick Sasse" <es****@newsgroups.nospam> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
This is not really a C# question, but I'm not sure which is the best
group to post it. Please, point me to the right one.

What's the best way to create a string from a repeated char? For
instance, I pass char = "*" and size = 5, and get a string = "*****".

I could write a function to loop size times and append to a
StringBuilder, but maybe there is something ready in the framework.

Thanks.

--
Erick Sasse

Feb 1 '06 #3
Bill Butler wrote:
One of the constructors for string takes a character and an int as
parameters. It does what you want.


Thanks Bill!

--
Erick Sasse
Feb 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Marcio Kleemann | last post by:
I need to force the first letter of each word in a line of text to uppercase. The text comes from a TextBox control in a Web Form. I'm new to ..NET and am having a problem. Since I can't modify...
5
by: MaSTeR | last post by:
Can anyone provide a practical short example of why in C# I shouldn't compare two strings with == ? If I write this in JAVA String string1 = "Widget"; if (string1 == "Widget") ...
4
by: Eric | last post by:
Initializes a new instance of the String class to the value indicated by a specified Unicode character repeated a specified number of times. String Constructor (Char, Int32) Why am I getting...
9
by: c_beginner | last post by:
Dear group, I want to implement a solution to the following link: http://acmicpc-live-archive.uva.es/nuevoportal/data/p2006.pdf As a beginning I am trying to implement this little sample...
14
by: Hugh Janus | last post by:
Hi all, I have several *long* strings (see bottom of post for an example) which I will be sending across a network. Therefore, I want to compress them for speed and because later they will be...
3
by: satyakarvvk | last post by:
Hi everybody! Please help me to overcome below runtime exception. Actually it is a simple program on basics. I want to print odd nos upto which the user asks and after printing the task,...
6
by: Bill Cunningham | last post by:
As I have been studing my tutorial I came up with this question. I took char passw(char name); and initialied this function in a header with other includes for standard library headers. This...
20
by: sophia | last post by:
Dear all, The following is the program which i have done to find all the combination of letters in the string "hello" #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX 5
1
by: TrippW06 | last post by:
I working on a program to analyze a string and tell the user how may of each char is in the sentence. I have it sorta working but cant fidgure it out. I get a weird last line and my method to remove...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.