473,321 Members | 1,748 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,321 software developers and data experts.

Create string of length X

When unit testing constraints of my business object, I oftentimes need
strings of a certain length. What characters are of no importance.

I'm looking for an elegant way of doing this.

Regards,
// Martin Rosén-Lidholm


Nov 16 '05 #1
6 2400
"Martin Rosén-Lidholm" <ma*****************@snabel-a.msn.com> wrote in
message news:eu**************@TK2MSFTNGP12.phx.gbl...
When unit testing constraints of my business object, I oftentimes need
strings of a certain length. What characters are of no importance.

I'm looking for an elegant way of doing this.

Regards,
// Martin Rosén-Lidholm

How about padding?
Nov 16 '05 #2
string s = new string('#', 20); // gives "####################"

Chris.

"Martin Rosén-Lidholm" wrote:
When unit testing constraints of my business object, I oftentimes need
strings of a certain length. What characters are of no importance.

I'm looking for an elegant way of doing this.

Regards,
// Martin Rosén-Lidholm


Nov 16 '05 #3
Thanks! :-)

// Martin
"Chris Ballard" <Ch**********@discussions.microsoft.com> wrote in message
news:DB**********************************@microsof t.com...
string s = new string('#', 20); // gives "####################"

Chris.

"Martin Rosén-Lidholm" wrote:
When unit testing constraints of my business object, I oftentimes need
strings of a certain length. What characters are of no importance.

I'm looking for an elegant way of doing this.

Regards,
// Martin Rosén-Lidholm


Nov 16 '05 #4
Hmmm, how about:

class Builder
{
static string MakeString(int iLength)
{
StringBuilder sb = new StringBuilder();

for(int i = 0; i < iLength; i++)
{
sb.Append('x');
}

return sb.ToString();
}
}

so, string str = Builder.MakeString(5); gives you: xxxxx
Nov 16 '05 #5
Just do

string s = new string('x', 100);

Jonathan Currie wrote:
Hmmm, how about:

class Builder
{
static string MakeString(int iLength)
{
StringBuilder sb = new StringBuilder();

for(int i = 0; i < iLength; i++)
{
sb.Append('x');
}

return sb.ToString();
}
}

so, string str = Builder.MakeString(5); gives you: xxxxx

Nov 16 '05 #6
string s = new string('x', 100);

Martin Rosén-Lidholm wrote:
When unit testing constraints of my business object, I oftentimes need
strings of a certain length. What characters are of no importance.

I'm looking for an elegant way of doing this.

Regards,
// Martin Rosén-Lidholm

Nov 16 '05 #7

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

Similar topics

2
by: Jim | last post by:
All of a sudden I am unable to create tables or add columns to existing tables if I specify CHARACTER greater than 254. If I try I get the following error: DB21034E The command was processed as...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
3
by: Miguel Dias Moura | last post by:
Hello, I am calling an ASP.NET / VB as follows: search.aspx?search=asp%20book%20london Then I create a string with the keywords like this: Dim keywords() As String =...
3
by: Kondapanaidu | last post by:
Hi, I am using .NET 1.1 along with 2K Professional Operating System. How to create a new drive in a system which is not available in my system. Example: My System is having the A,B,C,D,E...
4
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. Here is my problem. I have a program that will create a registry key, however it is not and here is the code and also the error that follows: ...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
7
by: Rob | last post by:
This actually compiles and works but it doesn't seem like the best code, so I was wondering is there another way to do this? template <typename Tvector<T>* addDepth(T) { return new vector<T>;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.