|
Hmmm - I didn't think of that. I guess I was looking for educational value, I assumed he wanted them to learn about how to use array indexes. Plus, he's insisting he can't use stuff that the question doesn't say.
What a *dumb* thing for a teacher to assign, if the answer is to use a stringbuilder. But, wait, how would they get substrings, etc ? I mean, they would then need to call methods on the string class, via the string returned from ToString, right ?
I reviewed the assignment, and while there's no substring, there is a reverse, and other methods such as finding the index of a string in another, that make me think that a stringbuilder is definately not the answer being sought, and that addressing chars in a string by index, is.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
No string operations are required at all once the raw data is available, and that is what
new StringBuilder(string) does. So basically it is used as a replacement for
the index operator, allowing an almost native implementation of string functions.
I do agree it isn't a very smart assignment.
|
|
|
|
|
You're saying there's a tostring on StringBuilder that takes indexes for substrings ?
That DOES make sense of not being allowed to use +, you don't need to.
How odd...
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Christian Graus wrote: You're saying there's a tostring on StringBuilder that takes indexes for substrings ?
I did not intend to say that, but yes it does exist.
Anyway one does not need it, access to the raw data plus some character moving is all it takes.
Import with the SB constructor, export with a simple SB.ToString.
|
|
|
|
|
He's not allowed to use foreach, I assume that means when he says he's not allowed to use [], he means at all, not just on the string class.
I bow to you, that just didn't occur to me, or anyone else.
I wonder if the goal is to fail anyone who gets the answer, b/c they must have asked on the web to get it ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Maybe, but the teacher should be a bit more clear and should give the students a hint, such as "you may want to look at the stringbuilder class"
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Oh, the assignment is useless. I think the main reason none of us got it is b/c it's not clear how you'd expect that to involve a learning objective. What do they learn from that ?
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Christian Graus wrote: the assignment is useless
Yes. It was very pointless, and it is not something I would subject my students to.
Christian Graus wrote: What do they learn from that ?
Not sure, other than to try and get other people to do their work for them. That is why I suggested the teacher should have given some kind of hint.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Five for you. I didn't even think of the StringBuilder class
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Luc Pattyn wrote: All it takes is StringBuilder class, with one of its constructors (string), and ToString().
Oh, circumventing the rule that no methods of the string class should be used, by using methods of another class... Sneaky...
Then there are some other alternatives to get at the data, like using the Encoding.UTF16.GetBytes method, or use a StreamWriter to write the string to a MemoryStream ...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Oh, circumventing the rule that no methods of the string class should be used, by using methods of another class... Sneaky...
Yeah, what's the use of .NET if you're not allowed to use any class method?
And if that is what it takes to answer a question, then probably the question itself is sneaky.
I can't help that.
|
|
|
|
|
An alternative, more adventurous, but all in all easier way is to use P/Invoke and some
native C code, so strlen, strcat, and the like can be used (they are not part of the String class!).
Now the input data can get passed down as string, and a sufficiently large StringBuilder
should be passed too to collect the resulting string, so ToString() can upgrade them to the
final result.
This way the exercise makes some sense.
|
|
|
|
|
OK - I'm interested. Type in the EXACT text of the assignment so we can all marvel at this. You've got a site full of professional developers here all telling you that this can't be done so at least one of the following conditions applies:
a) your understanding is wrong
b) this is the wrong forum and you are meant to be using a language like C
c) you have missed out a vital step or two
d) your professor is a complete thundering idiot and the assignment is wrong
e) you are way off beam with the foreach/indexer idea
Let's have a look so we can make our own mind up.
|
|
|
|
|
I think Luc found the answer. I can't imagine what the goal of this assignment was, in terms of learning something, but apparently, you can pass a string into a stringbuilder and use the stringbuilder to pull out substrings, and get the string length. You can use another stringbuilder to build a new string.
So, ultimately, the only thing I can think of, is that the professor hoped to create some research skills, or something.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Christian Graus wrote: the professor hoped to create some research skills
I hope that is the case. That is, to me, of more value than the ability to hack out the code for the assignment. This opens up the student to stronger analytical thinking skills/think-outside-the-box, etc.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Me thinks there is some missing details in the OP...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Pete O'Hanlon wrote: a) your understanding is wrong
I vote for that!
|
|
|
|
|
You don't need to post again if the other thread is getting long.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Seems like there is some information missing... Do you have any specification what the methods should do, really?
Sajjad Izadi wrote: public String insert (String st1, String st2, int len); //insert a string to an other
What is the len parameter supposed to do?
Where in one of the strings (which?) is the other supposed to be inserted?
Sajjad Izadi wrote: public int pos (String st1, String st2, int len); //return the position of specified string in an other specified string
What is the len parameter supposed to do?
Sajjad Izadi wrote: public int countOf (String st1, String st2, int len); //return number of repetitions of an string in an other string
What is the len parameter supposed to do?
Can the occurances of the string overlap, i.e. should countOf("aba", "ababa", whatever) return one or two?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi All,
I'm just looking around at getting something to perform this task on my projects and was wondering what folks here use or would recommened. If money was no object I'd like to go for Xenocode but I just can't justify $1600, another I looked at was SmartAssembly but for a £300 application they don't even provide bug fixes after purchase ... frankly I think that is outragous.
Anyway, would like to know your thoughts on this and any recommendations for things to look at would be great.
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
All obsfucators are expensive and a waste of money.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Hi Christian,
Do you not take any steps to protect your codebase in applications?
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I accept that using C# means my code cannot be protected.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Gotcha.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Considering most of the things you write have been done before, and theres probably a better and more generic example somewhere on the web, theres not much point considering protection. I don't think I've ever looked at an application and thought "I wonder how they did that?".
Even if people do think your application does something cool, they won't disassemble it, they'll be straight on here with "how to add three numbers together in dot net???? code plz!!!".
|
|
|
|