-
August 8th, 2011, 12:52 AM
#1
String Format
In
Code:
string y= "CodeGuru site"
string result = string.Format("%8s",y);
Is there a way that "%20s could be a dynamic text ?
Code:
string format = "site is %8s";
string result = string.Format(format,y);
to format the string outside the scope of development?
Cheers
-
August 8th, 2011, 01:59 PM
#2
Re: String Format
Just trying to inject a string into another? Use a placeholder such as...
Code:
string y = "CodeGuru site";
Console.WriteLine(string.Format("site is {0}", y));
-
August 9th, 2011, 01:29 AM
#3
Re: String Format
Originally Posted by fcronin
Just trying to inject a string into another? Use a placeholder such as...
Code:
string y = "CodeGuru site";
Console.WriteLine(string.Format("site is {0}", y));
Also, for Console.WriteLine you can omit the string.Format(...) call and just write:
Code:
string y = "CodeGuru site";
Console.WriteLine("site is {0}", y);
But you can use the way fcronin mentions when you aren't directly outputting to console (i.e. string the result in a string).
Best Regards,
BioPhysEngr
http://blog.biophysengr.net
--
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|