how can i write functions in String class without using any tools?
-
Christian Graus wrote:
the teacher is an idiot
Might be a safe bet. I don't even subject my CS students to worthless crap assignments. Assignments I push on them have some real meaning to them.
"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
Yeah, they should be learning things they can use, although I am always for students writing a list class that they will never use, for example.
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.
-
I think you need to re-read the assignment. You seem to be saying 'turn a string into a byte array without using any methods on the string class that would give you access to the contents of the string'.
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.
Didn't you mean to direct this to Sajjad? I'm not the one doing the assignment :-\
"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
-
So - are you meant to use telepathy? Your professor has effectively ruled out all useful constructs.
Deja View - the feeling that you've seen this post before.
I usually suggest prayer when people ask stuff like this.
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.
-
Yeah, they should be learning things they can use, although I am always for students writing a list class that they will never use, for example.
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:
always for students writing a list class that they will never use
Sure, it primes them up for writing code that never gets used because boss says otherwise, and writing something like a list class teaches the fundamentals of OOP.
Christian Graus wrote:
they should be learning things they can use
Exactly, since they will walk out of the classroom with, hopefully sharper skillsets that can be of value to them. I've had students in the past, who earned lower than average grades thank me for increasing their skillsets, though their academic grade doesn't necessarily reflect it.
"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
-
no but it's my homework :) and i have to write that till next two days!
I think you need to re-read the assignment. You seem to be saying 'turn a string into a byte array without using any methods on the string class that would give you access to the contents of the string'.
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.
-
Didn't you mean to direct this to Sajjad? I'm not the one doing the assignment :-\
"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, I hate it when people do 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.
-
Oh, I hate it when people do 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.
Oh well, no worries :-D
"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
-
Christian Graus wrote:
It sounds messy tho.
Gearing him up for real world maintenance projects, I suppose.
"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
-
I'll admit I have some code that is a maintenance nightmare, considered "job security" to a certain extent :rolleyes:
"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
-
how can i make my string to char[] without using any built-in classes or prepared methods, += and = or 'foreach' in C#? in an other expression, i want to (have to) write trim, insert, concat, countOf(char c) and etc without using any of methods or classes or foreach and even += or + in C#. how is that? please help, thanks.
-
I think either the teacher is an idiot, or the OP is wrong in his understanding
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.
Why does it have to be "or"?? Why not "and"?? ;)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Without using the built in members of the String class, you can't access it's data.
Despite everything, the person most likely to be fooling you next is yourself.
I was just wondering whether or not you can with unsafe code... could be fun... :suss: Howsabout this :-D :
private unsafe static void
F
(
string S
,
out char[] A
)
{
int index = 0 ;fixed ( char\* s = S ) { while ( s \[ index \] != '\\0' ) { index++ ; } A = new char \[ index \] ; fixed ( char\* a = A ) { while ( index >= 0 ) { a \[ index \] = s \[ index \] ; index-- ; } } } return ;
}
Or lambda expressions?
modified on Monday, July 7, 2008 11:47 PM
-
how can i make my string to char[] without using any built-in classes or prepared methods, += and = or 'foreach' in C#? in an other expression, i want to (have to) write trim, insert, concat, countOf(char c) and etc without using any of methods or classes or foreach and even += or + in C#. how is that? please help, thanks.
It could be an exercise intended to show that it can't be done. But probably it's poor communication.
-
how can i make my string to char[] without using any built-in classes or prepared methods, += and = or 'foreach' in C#? in an other expression, i want to (have to) write trim, insert, concat, countOf(char c) and etc without using any of methods or classes or foreach and even += or + in C#. how is that? please help, thanks.
Here are Left and Right Trim methods that don't access any methods of the String class, but I hope this isn't what the teacher is expecting.
private unsafe static void
LeftTrim
(
string Subject
,
System.Collections.Generic.HashSet<char> Chars
)
{
fixed ( char* subject = Subject )
{
int* length = (int*) subject - 1 ;
int front = 0 ;
int back = 0 ;while ( ( front < \*length ) && ( Chars.Contains ( \*(subject + front) ) ) ) { front++ ; } while ( front < \*length ) { \*(subject + back++) = \*(subject + front++) ; } \*length = back ; } return ;
}
private unsafe static void
RightTrim
(
string Subject
,
System.Collections.Generic.HashSet<char> Chars
)
{
fixed ( char* subject = Subject )
{
int* length = (int*) subject - 1 ;while ( ( \*length >= 0 ) && ( Chars.Contains ( \*(subject + \*length - 1) ) ) ) { (\*length)-- ; } } return ;
}