Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1113987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:56:22+00:00 2026-05-17T02:56:22+00:00

How can this easy to write (and read) string formatting routine be convert into

  • 0

How can this easy to write (and read) string formatting routine be convert into the “proper” String.Format equivalent code?

Int32 power;
Single voltage;
Int32 kVA;
Double powerFactor;

powerFactor = power / kVA;

label1.Text = 
      DateTime.Now.ToString() + ": " + 
      power.ToString() + "W,  " + 
      voltage.ToString() + "V "+
      "(pf "+(powerFactor*100.0).ToString()+"%)";

//label1.Text = String.Format("{g}: {0:g}W, {0:g}V (p.f. {0:0%}%)", 
//      DateTime.Now, power, voltage, powerFactor);

I’ve spent about 10 minutes trying to use String.Format; the person who documented it should be terminated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:56:22+00:00Added an answer on May 17, 2026 at 2:56 am
    string.Format("{0}: {1}W,  {2}V (pf {3}%",DateTime.Now,power,voltage,powerFactor*100)
    

    So, here is the thing that I think is confusing you. Every {0} is the index of the objects you are passing in. {0} is the first object, {1} the second, and so forth. You can also specify formats, widths, and other things too numerous to list here. I use SteveX string ref for most of my needs.

    label1.Text = String.Format("{0:g}: {1:g}W, {2:g}V (p.f. {3:0.0%})", 
          DateTime.Now, power, voltage, powerFactor);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working all day and I somehow can't get this probably easy task
In theory this seems easy but I just can't get my head around this...
I bet this is easy but been trying for a while and can't seem
Ok guys I imagine this is easy but I can't seem to find how
I am sure this is easy - but I can't figure it out right
This should be easy to find out but I can't seem to find it
I know this is an easy question but I can't figure it out or
I know this is an easy concept, but I just can't seem to get
This sounds ridiculously easy, and it is with other shells. But I can't seem
An easy problem, but for some reason I just can't figure this out today.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.