As mentioned before StringForm together with ToString will give the desired results.
Here are some examples, that reproduce the functionality that is provided in other languages by sprintf (or similar functions):
myStrings = {
ToString[StringForm["This is a floating point: `1`\n" ,
ToString[NumberForm[5.6 10^9, NumberFormat -> (SequenceForm[#1, "e", #3] &)]]
]],
ToString[StringForm["This is a integer in blocks : `1`\n" ,
ToString[NumberForm[10^9, DigitBlock -> 3]]
]],
ToString[StringForm["This is a number with funny padding : `1` " ,
ToString[NumberForm[6.888, {7, 3}, NumberPadding -> {"_", "0"}]]
]],
ToString[StringForm["This is just a string : `1` " , "FOO"]]
};
myCompleteString = StringJoin[myStrings]
FullForm[myCompleteString]
Export["text.txt", myCompleteString, "Text"]
this will give you:
This is a floating point: 5.6e9
This is a integer in blocks : 1,000,000,000
This is a number with funny padding : ____6.888 This isjust a string : FOO
"This is a floating point: 5.6e9\nThis is a integer in blocks : 1,000,000,000\nThis is a number with funny padding : ____6.888 This is just a string : FOO "
and a file text.txt with the expected output.
See also these discussions:
*) Converting a large floating-point number to a single-line string
*) sprintf() or close equivalent, or re-implementation?
Attributes[StringForm]$\endgroup$Attributes[StringForm]gives{Protected}(version 8.4). $\endgroup$