[Solved] [C#] How to add dashes in Strings?

Discussion in 'Mixed Languages' started by example12345678912345678, Feb 20, 2022.

  1. example12345678912345678

    example12345678912345678 MDL Senior Member

    Dec 29, 2019
    498
    230
    10
    Hi, I'm having a problem. I need to combine three string values by adding dashes.
    But I can't due to this error:
    Code:
    The '-' operator cannot be applied to operands of type 'string' and 'string' (CS0019)
    DDMMYYYY to DD-MM-YYYY
    Example: 20022022 to 20-02-2022
    My code is:
    Code:
    string DD = numericUpDown1.Text;
    string MM = numericUpDown2.Text;
    string YYYY = numericUpDown3.Text;
    string BIOSDate = DD-MM-YYYY;
    System.Diagnostics.Process.Start("C:\\Windows\\system32\\cmd.exe", "/c date BIOSDate");
    Thank you so much.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Hunterrules0_0

    Hunterrules0_0 MDL Member

    Nov 27, 2021
    101
    32
    10
    hmmm let me see what I can do
     
  3. example12345678912345678

    example12345678912345678 MDL Senior Member

    Dec 29, 2019
    498
    230
    10
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,588
    340
  5. example12345678912345678

    example12345678912345678 MDL Senior Member

    Dec 29, 2019
    498
    230
    10
    Thanks for suggestion. But I get this error either way:
    Screenshot.PNG
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    18,681
    18,588
    340
    @example12345678912345678

    You're taking the year in 4 digits, while the "date" parameter only accepts it in two digits (YY) format.
     
  7. example12345678912345678

    example12345678912345678 MDL Senior Member

    Dec 29, 2019
    498
    230
    10
    I think I forgot to say. It looks like I should not use strings inside brackets. But fixed this error when I use strings outside of brackets. Thanks for help anyways.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...