[PR #422] Add + to positive offsets in a better way #1013

Open
opened 2026-01-29 16:24:49 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/SabreTools/MPF/pull/422

State: closed
Merged: Yes


Suppresses excessive "+".
I don't know C#, please modify accordingly.

string[] offsets = new string[] { "-1", "0", "1", "+1", "", "abc", null };

// current
foreach (string o in offsets) {
    string offset = o;
    if (offset?.StartsWith("-") == false)
        offset = $"+{offset}";
    System.Console.Write("[" + offset + "] ");
}
//=> [-1] [+0] [+1] [++1] [+] [+abc] [] 

System.Console.WriteLine();

// this PR
foreach (string o in offsets) {
    string offset = o;
    if (Int32.TryParse(offset, out int i))
        offset = i.ToString("+#;-#;0");
    System.Console.Write("[" + offset + "] ");
}
//=> [-1] [0] [+1] [+1] [] [abc] [] 
**Original Pull Request:** https://github.com/SabreTools/MPF/pull/422 **State:** closed **Merged:** Yes --- Suppresses excessive "+". I don't know C#, please modify accordingly. ```c# string[] offsets = new string[] { "-1", "0", "1", "+1", "", "abc", null }; // current foreach (string o in offsets) { string offset = o; if (offset?.StartsWith("-") == false) offset = $"+{offset}"; System.Console.Write("[" + offset + "] "); } //=> [-1] [+0] [+1] [++1] [+] [+abc] [] System.Console.WriteLine(); // this PR foreach (string o in offsets) { string offset = o; if (Int32.TryParse(offset, out int i)) offset = i.ToString("+#;-#;0"); System.Console.Write("[" + offset + "] "); } //=> [-1] [0] [+1] [+1] [] [abc] [] ```
claunia added the pull-request label 2026-01-29 16:24:49 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SabreTools/MPF#1013