|
Or you could use padding. For example you can define 200 characters for the title by padding all book titles during print out.
string sCurBookColumnValue = "MyBook".PadRight(200).
Do this for all values, this will format your string while writing it on the console.
|
|
|
|
|
Ahhh, so you need to parse the string, and then you want to make it pretty when you print by lining up columns of data...
I'm assuming that it's a console application (because making it pretty in a forms app would be much easier, and less work to boot).
You could brute-force it and use string.Format to pad each string, or you could read in the data, parse each string to find the longest name, publisher, etc., and then format with appropriate padding for each column. I think he first way would earn you a passing grade, and would take far less time, but the second way would teach you more (and be more fun besides).
Which path will you take?
My advice is to satisfy the minimum requirements by doing it the first way, but then do it the second way and if you finish it in time, hand the 2nd version in instead.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
|
Looking for some ideas on a framework for managing a 2 dimensional(dynamic size) array of objects. Something like a grid where one can access by row and column
|
|
|
|
|
Would a System.Collections.Generic.Dictionary<tkey,> suffice?
I are troll
|
|
|
|
|
Maybe you could try a List of Lists?
then write a function for getting with row column parameters
|
|
|
|
|
List<object> objCols = new List<object>();
List<list> objRows = new List<list>();
object GetCell(int row, int col)
{
return objRows[row][col];
}
Not tested but something along those lines perhaps
BTW 'List' can be found in System.Collections.Generic
modified on Friday, January 30, 2009 9:44 AM
|
|
|
|
|
Yes this sort of makes sense. I'll have to play with it a bit
thanks.
dale
|
|
|
|
|
Use the Dictionary object.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi John, I'm not familiar with this Dictionary approach. Would you have a small snippet that might help.
|
|
|
|
|
I can't give you anything better than you'd find on google. Search on "C# Dictionary Collections". You'll get a gazillion examples.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
|
Hi, and thanks for your interest.
I am trying to run MS Robocopy from a service with the following code:
Process robo = new Process();
robo.StartInfo.FileName = "robocopy.exe";
robo.StartInfo.Arguments = "g:\\data *.pdf d:\\data\\pdf\\ /S /NP /Log+:c:\\logs\\robo\\robo.log";
robo.Start();
The service starts but the Robocopy process fails to start. Any help greatly appreciated.
C. Richard Wenger
System Administrator
|
|
|
|
|
your filename prob needs to be the full path of the executable
|
|
|
|
|
I dropped the Robocopy.exe in the system32 folder just to have it in the path and eliminate those issues and on your advice I included the full path to the executable but it still doesn't appear to be executing?
C. Richard Wenger
System Administrator
|
|
|
|
|
well as your only setting 2 things (filepath, and parameters) are you sure the parameter string is valid? I.e. tested with CMD or something?
I never used Robocopy so i wouldnt know the params, if both are valid then i would guess the problem is else where in your code.
What functionality does Robocopy do? is it not something you can code yiurself
|
|
|
|
|
Try running your service under a user account instead of LocalSystem and see what happens.
|
|
|
|
|
What does this do? I haven't been able to find a suitable explanation as to what it does and i found it in some code that someone gave me.
|
|
|
|
|
i think its something along the lines of:
If a is true, then result is b, otherwise result is c
|
|
|
|
|
x = a ? b : c;
is the shorthand version of
if (a)
{
x = b;
}
else
{
x = c;
}
|
|
|
|
|
Except that ?: counts as an expression, instead of a statement. So there are more places where you're allowed to use it.
Such as:
if (a?b:c) { }
or
int x = a?b:c;
(that doesn't mean you're wrong, I just think it might help bfis108137 to know that)
|
|
|
|
|
It's known as a ternary operator. Basically, this is an operator that reads like this: "If the condition is true then use the value immediately after the question mark, otherwise use the value after the colon". Another operator you may sometimes see is the ?? operator. This is known as the coalescing null operator, and is used in statements like this:
MyClass a = value1 ?? value2 ?? new MyClass(); This reads like this "MyClass a is assigned value1, unless value1 is null in which case, it will use value2, unless value2 is null in which cass it uses new MyClass();" This is an efficient way to assign a default value if a null value is encountered.
|
|
|
|
|
|
It's called a ternary operation, and is the shortcut of doing this:
int z = 0;
int x = 1;
int y = 2;
if (x==y)
{
z = x;
}
else
{
z = y;
}
z = (x ==y) ? x : y;
Many high-browed programmers don't like it, but as long as you keep it to just one comparison instead of stacking them, I think it's an acceptable coding practice.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Right, it should not be abused; I would not use it as z = (x ==y) ? x : y; , because an if statement would work for that.
One situation I use it in is something like this:
string.Format
(
"{0} record{1} processed."
,
count
,
count==1?"":"s"
) ;
I find this more readable than the alternatives.
Whenever I see an application write something like, "1 records processed", I . Come on, guys, use the ternary operator!
|
|
|
|