473,569 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2268
"Erick Sasse" <es****@newsgro ups.nospam> wrote in message
news:eZ******** ******@TK2MSFTN GP15.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****@newsgro ups.nospam> wrote in message
news:eZ******** ******@TK2MSFTN GP15.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
7916
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 the string directly, I convert the string to a char using .ToCharArray() and set the first letter of each word to uppercase. The problem then is I...
5
657
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") System.Console.WriteLine("String1 Equal.");
4
1434
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 these errors: 1) C2078: too many initializers and 2) C2440: 'initializing' : cannot convert from 'int' to 'System::String __gc *'
9
3949
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 program which will delete the repeated strings in two set of strings.
14
3632
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 stored in a DB. I found this code here http://abstractvb.com/code.asp?A=931 but it doesn't seem to give me a particuarly good level of compression it...
3
52508
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, again i will ask user whether he want to continue again and the process is repeated. My code is working first time normally but after user says...
6
1789
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 doesn't seem to work so is what I want this? char passw(char *name); I haven't got to pointers in the tutorial and I'm taking my time. But in this...
20
2975
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
4368
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 the "." totally kills the program. I had java several years ago and a friend has asked me to help. Any Ideas? import java.util.*; import...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7682
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
954
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.