Backspace in string formatting while printing to PDF

前端 未结 3 1526
刺人心
刺人心 2021-01-20 04:54

I\'m trying to print in PDF two columns of information that contain some strings that the user inputs. This is my code so far:

string s = \"\";
int width = 6         


        
3条回答
  •  伪装坚强ぢ
    2021-01-20 05:47

    i have tried this below. It worked for me. you are using (60 - name.size) for name width but you are not using (name.width) for AAA. if you use this then total width will be = (60 - name.size) + name.size = 60. [I think this is what you are wanting.]. good luck.

    string name = "John Edward Jr.";
            string surname = "Pascal Einstein W. Alfi";
            string school = "St. John";
            string s = "";
            int charWidth = 0;
            int width = 60 - name.Count();
            charWidth = name.Count();
            s = s + string.Format("{0,-" + width + "}" + "{1," + charWidth + "}", "Name: " + name, "AAA: ");
            Console.WriteLine(s);
            s = "";
            width = 60 - surname.Count();
            charWidth = surname.Count();
            s = s + string.Format("{0,-" + width + "}" + "{1," + charWidth + "}", "Surname: " + surname, "BBB: ");
            Console.WriteLine(s);
            s = "";
            width = 60 - school.Count();
            charWidth = school.Count();
            s = s + string.Format("{0,-" + width + "}" + "{1," + charWidth + "}", "School: " + school, "CCC: ");
            Console.WriteLine(s);
    

提交回复
热议问题