allow user edit format string

  • Thread starter Thread starter bbla32
  • Start date Start date
B

bbla32

Hey, is there a fast way to change a string used for formatting, like

Value:\t{0}\r\n

to string that user can edit, like:

Value:\\t{0}\\r\\n

In other words, I want user to be able to edit a format string. Is
there a quicker way than

format.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\
\t"). ....
 
I guess you lost me. Why is the second string easier for the user to edit?

If you ask the user for a formatting string from a textbox, then you just
use it like any other formatting string.
 
I guess you lost me.  Why is the second string easier for the user to edit?

If you ask the user for a formatting string from a textbox, then you just
use it like any other formatting string.

Let me give an example.
formatString = "{0}\n";
Console.Write(string.Format(formatString, 1)); // prints "1" and
newline.
// now let user edit it...
textBox1.Text = formatString; // it displays "{0}" followed by a box,
because it cannot display the newline character \n.
// I wish the user sees "{0}\n", so textBox1.Text should contain "{0}\
\n", which should be converted back to "{0}\n" after editing.
 
Now I got what your doing. I don't see any way except for showing two
slashes in the text box and replacing on use as you did.

I guess you lost me. Why is the second string easier for the user to edit?

If you ask the user for a formatting string from a textbox, then you just
use it like any other formatting string.

Let me give an example.
formatString = "{0}\n";
Console.Write(string.Format(formatString, 1)); // prints "1" and
newline.
// now let user edit it...
textBox1.Text = formatString; // it displays "{0}" followed by a box,
because it cannot display the newline character \n.
// I wish the user sees "{0}\n", so textBox1.Text should contain "{0}\
\n", which should be converted back to "{0}\n" after editing.
 
Back
Top