0

I have three strings that I need to write into a file without any new lines and have them within fixed width fields. currently im trying to use printwriter's printf but i dont fully understand how to do it. if this isnt enough info please ask and ill do my best to clarify my question.

2
  • Do you need your newlines simply removed from the strings? And what is "within fixed with fields"? Commented Feb 16, 2012 at 19:50
  • I think he means that it should be space filled if the data cannot take the entire field (space padded) so that the field is always the same length Commented Feb 16, 2012 at 20:01

1 Answer 1

2

If you have 3 strings, a, b and c, you should be able to use something like this...

printf("a=%-20s b=%-20s c=%-20s", a, b, c);

This will left align your strings and they will be fixed at a width of 20 each.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.