This thread should help. That post has some suggestions for simple formatting. To get really good formatting, I have a “one line” external function that calls the C function, sprintf. I can repost it here if you are interested.
Appreciate your help. I went through the post and the other one mentioned there. Not understood all the steps yet, but my problem is more of copying a numerical value after a string in the text file, rather than changing its accuracy or format. I am bit confused now, whether I need to convert the string to CForm for Mathematica to read it in the text file. However, my previous experience is that Mathematica can read a string in a text file, as it is. Please correct me if I am wrong.
In my case, it would be fine if I am able to copy a number in its given form, as long as it is of correct numerical value for all possible formats. For example, if the number is 1.23e2 in the text file, I am not worried whether I get the output as 1.23e2 or 123 or 123.00 or 1.23*10^2 etc.
Hope it explains my problem little better. Thanks once again.
Not really. 1.23e2 is not a valid format for a number in WL. 1.23*^2 or 1.23*10^2 are valid. The code I provided converts the invalid form to the valid one and the result is a number, not a string.
If you want a string result then just split the string
Read::readn: Invalid real number found when reading from StringToStream[pqr : = 5].
This point is important as I have to use this method to extract a parameter from a text file having large number of strings, each followed by a number.
Well, now you have changed the requirements. It would have been better if your original question stated the requirements clearly and completely.
Actually, I mentioned that I need to copy a number from the text file, after a particular string. Anyways, finally, StringSplit worked, however I had to make some changes to what you suggested. Thanks for the help.