|
Write out a backspace character, then a space! The space overwites the last char. Not sure how you would actually remove it completely but, y'know.
Console.Write("\b ");
Should replace the last char with a space.
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Console.Write("\b \b"); should do it.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Oh, sure, just give him the whole solution, geeze.
|
|
|
|
|
Howdy people,
I was wondering if any of you serialization experts know if this is possible. I've trawled through MSDN a few times, but no luck so far.
I have an XML document like this:
<Item>
<ID>1</ID>
<SubItem>test1</SubItem>
<SubItem>test2</SubItem>
<SubItem>test3</SubItem>
<SubItem>test4</SubItem>
</Item>
And at the end of it, I want to end up with:
class MySuperDuperClass {
public string ID
public string[] SubItems
}
Any ideas if this is doable with plain serialization? Or is working with the XML nodes/queries the only way to go?
- Phil
|
|
|
|
|
I feel you can do this easily using XML nodes/queries. So why you are considering serialization ? Sorry If I misunderstood your question.
|
|
|
|
|
Thanks for your answer Navaneeth. It can definitely be done easily without serialization, and I am just investigating if it is even possible to do it with serialization.
- Phil
|
|
|
|
|
Phil Martin... wrote: nd I am just investigating if it is even possible to do it with serialization.
Yes it is possible. Check this[^]
Hope this helps
|
|
|
|
|
That is perfect, thanks Navaneeth.
I just couldn't get the right combination of XmlAttributes, but that works a treat.
Thanks!
- Phil
|
|
|
|
|
Welcome, Glad to know that it worked. I used this to create a serializable class to send across a TCP connection.
|
|
|
|
|
Hi everyone,
I had a job interview yesterday, and they asked me to solve this problem:
---
Given any number of words (ie. "I went driving in my car"), make a method that will return the words in reverse (ie. "car my in driving went I").
private string Swap(string input)
{
//insert code here.
}
---
They showed me there ruby on rails solution which they did with 2-3 lines.
100 points for anyone who can come up with a C# solution that competes with their ruby one.
Cheers Mark.
|
|
|
|
|
Here is some code which will do that in 1 line
string[] initial=input.split(' ');string[] rval=new string[initial.Length];for(int i=0;i<initial.Length;i++)rval[initial.Length-i-1]=initial[i];return rval;
Technical programmers say to have whitespace, but what do they know.
Even still when their is whitespace it does not add up to less than or equal to 3 lines, impossible in C#.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[^]
|
|
|
|
|
Sorry, a ; is a line delimiter.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
No it's not. It is a statement delimiter. However, normally you don't have more than one statement per line.
|
|
|
|
|
That's nit picking. You know what I meant. When someone says 'do this in 'x' lines', concatenating logical lines, which makes code harder to read, doesn't count.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
public static string wordReverse(string s) {return string.Join(" ",Array.Reverse(s.Split(" ")));}
public static string wordReverse(string s) {
string[] sa=s.Split(" ");
Array.Reverse(sa);
return string.Join(" ",sa);
will reverse the order of words when word=sequence of chars delimited by spaces;
it will fail for sentences having punctuation (your example has none), they would
require a lot more code to get handled correctly in all cases.
public static string wordReverse(string s) {return string.Join(" ",Array.Reverse(s.SubString(0,s.Length-1).Split(" ")))+s.SubString(s.Length-1);}
public static string wordReverse(string s) {
string[] sa=s.SubString(0,s.Length-1).Split(" ");
Array.Reverse(sa);
return string.Join(" ",sa)+s.SubString(s.Length-1);
which preserves the final punctuation, assuming one is present.
And you could add a test to see if the final character is one of ".;:?!" to choose one
or the other. LastIndexOf could help here.
-- modified at 16:01 Thursday 22nd November, 2007
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks Luc,
Hopefully in a few years i'll be able to code like you and someone might want to hire me
Mark.
|
|
|
|
|
Hi Mark,
don't give up; if you ask me such a test is plain silly, they should look
for analytic and synthetic power, logic, energy, thoroughness, not fancy coding.
Anyhow experience and study will guide you.
Read some books; study some CP articles. And yes, read up on the important classes, one by one,
so you get a good grip on their functionality, not their details.
BTW: how will I receive my 100 pts?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: how will I receive my 100 pts?
Here you go, Luc:
Point[] pts = new Point [100];
/ravi
|
|
|
|
|
Many thanks.
Yet another collection I can reverse...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Wow, the for loops i could have avoided had i know about Array.Reverse()
Good job i've only ever reversed an array once
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
C# 3 (the version that will be released within a month or two) has a feature called extension methods that allow you to do something like you'd see the Ruby version do.
Because of generic extension methods, you can do this in C# 3:
string Swap(string input)
{
return input.Split(' ').Reverse().Aggregate((first, second) => first + " " + second);
}
Now, that's doing it all in 1 line and it's not too bad. That said, you might want to comment it, break it up, and make it easier for humans to read. Something like this might be more readable to humans:
string Swap(string input)
{
string[] words = input.Split(' ');
IEnumerable<string> reversedWords = words.Reverse();
return reversedWords.Aggregate((first, second) => first + " " + second);
}
|
|
|
|
|
hi,
i have a managed library(not application) that requires some unmanaged dlls, is there a way to emmbed a manifest or some other way to make it "xcopy distributable"?
* the problem is that the unmanaged dlls reside with the lib and not the application.
|
|
|
|
|
I feel like this should be obvious, but I haven't found it yet. Does anyone know how to get a Property Grid to display an int or byte property value in hex?
"We may not be the smartest in the world, but we're the smartest you've got."
-a co-worker, speaking to our manager
|
|
|
|
|
Call ToString("X") on your int/byte variable to return a string representation of its value in hexadecimal format.
Paul Marfleet
|
|
|
|