|
Today i have a unique requirement which i am going to explain with an example
My String
string s = "aaaabcc";
Now i want to use 2 replace functions at same time. so, answer would be like this:-
OUTPUT
ccccbaa
Till now i don't know how to start as when i write
string s = "aaaabcc";
s = s.Replace("a","c").Replace("c","a");
the answer goes wrong cause last replace function removes the newly added char.
Can anyone help me here any piece of code snippet would be helpful
Thanks in advance
|
|
|
|
|
You need to use an interim character that is neither a nor c. Something like:
string s = "aaaabcc";
s = s.Replace("a","#").Replace("c","a").Replace("#","c");
|
|
|
|
|
|
Please do not post the same question in more than one place, you already got an answer in QA.
|
|
|
|
|
sorry for that need reply urgently but i think i will wait till the perfect answer
|
|
|
|
|
A thing to remember. This is a volunteer site. Just because something is urgent for you doesn't mean that there's any urgency for an answer. Ironically, asking in more than one location dilutes your chance of getting the answer you need in your timeframes.
In other words, when posting a question, show some patience.
|
|
|
|
|
yes sir, i understand and i apologized for it already but can you help me in this question?
|
|
|
|
|
You have already been helped.
|
|
|
|
|
While no answer is perfect, I'd be wondering how you are going to recognize it. I'd also like to point out that there is a slight contradiction in "waiting urgently".
If "all the characters are taken", then you'd introduce the concept of an escape-character (or multiple). It was also a bit premature to shout that all characters are taken, as various encodings allow for fewer or more characters.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
.. and please stop cross posting in different forums - Medhi also gave you a similar answer in the other forum you posted this question - ok, so, he didn't chain the replaces, no big deal
|
|
|
|
|
s = string.Join( "", s.Select( ch => ch == 'a' ? 'c' : ch == 'c' ? 'a' : ch ) );
|
|
|
|
|
sir it is giving compilation error sir please try to fix it and update the answer
|
|
|
|
|
You're expected to do some of the work yourself. We don't get paid to write code for you.
|
|
|
|
|
What do I get if I "fix" it?
It's a "code fragment" that conveys the essence of your question.
Do you know what a "code fragment" is?
Do you know what LINQ is?
Do you know what a "using" statement is used for?
|
|
|
|
|
That may be correct but I know I can understand the Replace() structure one hell of a lot easier that your linq solution. I guess it takes a particular mental bent to look at that and have it go 'click' and understand it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You're right.
Replace() is fine if one is always content just to use the first thing that comes to mind.
If I needed to use something similar in an intensive production situation, I would benchmark "all" scenarios and go with the one that performed best; "bent" or not.
I thought it was an interesting exercise.
But then again, I've also spent a lot of time with LINQ and don't feel the need to dumb myself down because someone else might not get it (or bother trying); after all, it's just a select, a couple of "if's", and a join ...
|
|
|
|
|
If performance was an issue I could understand benchmarking the processes, that aside, I always go for the most supportable because the poor sod who has to support the app down the track may not understand the linq but would certainly understand the Replace option.
As a response to a newbies question (which already has a simple solution) it is valid, he may look at that and go Ahhh I get it!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
|
The message from Thomas says that you need to recompile PDFSharp (specifically the PdfSharp.Charting assembly) with the changes he's suggested.
You can find both classes in the folder: PDFsharp\code\PdfSharp.Charting\PdfSharp.Charting.Renderers
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi!
Works great! But i also had to add
using PdfSharp.Pdf
to RendererInfo.cs, to make the application run.
Thank you very much!
|
|
|
|
|
Hello. I am placing 4 dots on an image (1280x720) using mouse click. Now I crop this image of size just bigger than these 4 dots (coords). How do I place the 4 coordinates on the cropped image ? Thanks for any pointer.
|
|
|
|
|
If you place the 4 dots, then crop the image to a size that is larger than the hypothetical rectangular bounding region enclosing the dots: q.e.d. they are visible on the cropped image.
So the question becomes: what principle/rule/heuristic do you want to apply to re-positioning the dots.
Are there any constraints on where the dots are placed initially, or what their relationship is with each spatially ?
Details, please.
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|
|
Actually these 4 dots represent the four coordinates of a rectangle that I use to crop the image. And yes, the cropped image is bigger than the 4 dots. Now I have no clue what should be done to redraw the dots on the cropped image. (This is knows as "re scaling" perhaps.)
modified 31-Oct-14 3:21am.
|
|
|
|
|
I think my head is a little slow today, so bear with me: if you use the 4 dots to define a rectangle for cropping, and the cropping is performed, do you then need to show the 4 dots after the crop ?
It's a typical convention in UI design for resize/crop "handles" to appear when some run-time object is selected, but perhaps you are working with a different design idea ?
« I am putting myself to the fullest possible use which is all, I think, that any conscious entity can ever hope to do » HAL (Heuristically programmed ALgorithmic computer) in "2001, A Space Odyssey"
|
|
|
|