Where is string.Reverse() and string.SwapChars()?

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

Is it just me? It seems like one moving from MFC to C# loses some string
functionality such as the two mentioned in the subject.

Did I miss something?
 
Hello Jonathan,

Reverse is the method of Array class, thus u can convert string to array
and reverse array
For swapping use String.Replace

JW> Is it just me? It seems like one moving from MFC to C# loses some
JW> string functionality such as the two mentioned in the subject.
JW>
JW> Did I miss something?
JW>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Thanks but there are a few things like this that really irk me about C# and
..NET.

Why not add a Reverse method? It's very simple for Microsoft to do. On the
other hand, converting the string to an array, reversing it, and then
converting it back to a string requires additional memory allocations, etc.
that greatly reduce the efficiency of this simple task. If the language is
not going to allow us to perform certain tasks (such as swapping two
characters without create a new string), the least they could do is
implement a simple Reverse method.

I guess I'm having trouble with this overall mentality of limiting what we
can do, especially when simple functionality has not been included for us.

Must just be me.
 
other hand, converting the string to an array, reversing it, and then
converting it back to a string requires additional memory allocations, etc.

See the StringBuilder class - it is mutable



Jonathan Wood said:
Thanks but there are a few things like this that really irk me about C# and
..NET.

Why not add a Reverse method? It's very simple for Microsoft to do. On the
other hand, converting the string to an array, reversing it, and then
converting it back to a string requires additional memory allocations, etc.
that greatly reduce the efficiency of this simple task. If the language is
not going to allow us to perform certain tasks (such as swapping two
characters without create a new string), the least they could do is
implement a simple Reverse method.

I guess I'm having trouble with this overall mentality of limiting what we
can do, especially when simple functionality has not been included for us.

Must just be me.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


Michael Nemtsev said:
Hello Jonathan,

Reverse is the method of Array class, thus u can convert string to array
and reverse array
For swapping use String.Replace

JW> Is it just me? It seems like one moving from MFC to C# loses some
JW> string functionality such as the two mentioned in the subject.
JW> JW> Did I miss something?
JW> ---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche
 
Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

KH said:
other hand, converting the string to an array, reversing it, and then
converting it back to a string requires additional memory allocations,
etc.

See the StringBuilder class - it is mutable



Jonathan Wood said:
Thanks but there are a few things like this that really irk me about C#
and
..NET.

Why not add a Reverse method? It's very simple for Microsoft to do. On
the
other hand, converting the string to an array, reversing it, and then
converting it back to a string requires additional memory allocations,
etc.
that greatly reduce the efficiency of this simple task. If the language
is
not going to allow us to perform certain tasks (such as swapping two
characters without create a new string), the least they could do is
implement a simple Reverse method.

I guess I'm having trouble with this overall mentality of limiting what
we
can do, especially when simple functionality has not been included for
us.

Must just be me.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


Michael Nemtsev said:
Hello Jonathan,

Reverse is the method of Array class, thus u can convert string to
array
and reverse array
For swapping use String.Replace

JW> Is it just me? It seems like one moving from MFC to C# loses some
JW> string functionality such as the two mentioned in the subject.
JW> JW> Did I miss something?
JW> ---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top