c# - Add one space after every two characters and add a character infront of every single character -
c# - Add one space after every two characters and add a character infront of every single character -
i want add together 1 space after every 2 characters, , add together character in front end of every single character.
this code:
string str2; str2 = str1.tochararray().aggregate("", (result, c) => result += ((!string.isnullorempty(result) && (result.length + 1) % 3 == 0) ? " " : "") + c.tostring()); i have no problems separating every 2 characters 1 space, how know if separated string has individual character, , add together character infront of character?
i understand question confusing i'm not sure how set want in words.. i'll give example:
i have string:
0123457 after separating every 2 characters space, i'll get:
01 23 45 7 i want add together 6 infront of 7.
note: numbers dependent on user's input, it's not same.
thanks.
i think asked for
string str1 = "3322356"; string str2; str2 = string.join(" ", str1.tochararray().aggregate("", (result, c) => result += ((!string.isnullorempty(result) && (result.length + 1) % 3 == 0) ? " " : "") + c.tostring()) .split(' ').tolist().select( x => x.length == 1 ? string.format("{0}{1}", int32.parse(x) - 1, x) : x).toarray()); result "33 22 35 56"
c# string
Comments
Post a Comment