Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# string.format add a "-" value?

I have a string.format issue ...

I'm trying to pass my invoice ID as an arguments to my program ... and the 6th argument always end up with "-" no matter what I do ( we must use the ¿ because of an old program ) ...

     public static void OpenIdInvoice(string wdlName, string IdInvoice, Form sender){
        MessageBox.Show(string.Format("¿{0}",IdInvoice));
        proc.Arguments = string.Format("{0}¿{1}¿{2}¿{3}¿{4}¿­{5}",
            session.SessionId.ToString(),
            Session.GetCurrentDatabaseName(),
            session.Librairie,
            wdlName,
            "",
            IdInvoice
        );
        System.Windows.Forms.MessageBox.Show(proc.Arguments);

In the end, "-" is always added to my formatted result, but only before my IdInvoice ... (so Id 10 ends up -10 in my Arguments )

now the fun part ... I hardcode some string and ...

if I pass -1 instead of an Id, I have --1 as a result and If I write "banana" ... i get "-banana" ...

I know I could just build the string otherwise ... but I'm getting curious as to why it happens.

Here's the screenshot  minus banana ? ...

EDIT :

thats the copy/paste of my code

var proc = new System.Diagnostics.ProcessStartInfo("Achat.exe");
        System.Windows.Forms.MessageBox.Show(string.Format("¿{0}",args));
        proc.Arguments = string.Format(@"{0}¿{1}¿{2}¿{3}¿{4}¿­{5}¿{6}",
            "12346", //session.SessionId.ToString(),
            "fake DB",//Session.GetCurrentDatabaseName().ToString(),
            "false", //session.Librairie.ToString(),
            "myScreenName", //wdl.ToString(),
            "123456",
            "Banana",
            "123456"
            //args.ToString(), 

        );
        System.Windows.Forms.MessageBox.Show(proc.Arguments);
        System.Windows.Forms.MessageBox.Show(args);

and thats the copy/paste of my text visualiser result :

12346¿fake DB¿false¿myScreenName¿123456¿­Banana¿123456

like image 964
Thierry Savard Saucier Avatar asked Mar 24 '17 19:03

Thierry Savard Saucier


1 Answers

You literally have an extra character before "{5}" that's called a soft hyphen. It's one of those weird characters that isn't always displayed. If you place your cursor after the "{" in "{5}" and press the left arrow and then press backspace it will actually delete it. That or you can try to use an editor like Notepad++ that will display it. I was able to find it by running the following code

var t = @"{0}¿{1}¿{2}¿{3}¿{4}¿­{5}";
foreach (var c in t)
{
    Console.WriteLine((int)c + " " + c);
}

which printed out

123 {
48 0
125 }
191 ¿
123 {
49 1
125 }
191 ¿
123 {
50 2
125 }
191 ¿
123 {
51 3
125 }
191 ¿
123 {
52 4
125 }
191 ¿
173 -
123 {
53 5
125 }
like image 179
juharr Avatar answered Oct 19 '22 03:10

juharr