CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: String Format

  1. #1
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    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

  2. #2
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    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));

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: String Format

    Quote Originally Posted by fcronin View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured