string.format

Currency Formatting MVC

吃可爱长大的小学妹 提交于 2019-11-26 22:23:33
问题 I'm trying to format an Html.EditorFor textbox to have currency formatting, I am trying to base it off of this thread String.Format for currency on a TextBoxFor. However, my text just still shows up as 0.00 with no currency formatting. <div class="editor-field"> @Html.EditorFor(model => model.Project.GoalAmount, new { @class = "editor- field", Value = String.Format("{0:C}", Model.Project.GoalAmount) }) There is the code for what I am doing, and here is the html for that field in the website

vsprintf or sprintf with named arguments, or simple template parsing in PHP

戏子无情 提交于 2019-11-26 20:57:15
问题 I'm searching for a way to use named arguments for sprintf or printf . Example: sprintf( 'Last time logged in was %hours hours, %minutes minutes, %seconds seconds ago' ,$hours,$minutes, $seconds ); or via vsprintf and an associative array. I have found some coding examples here function sprintfn ($format, array $args = array()) http://php.net/manual/de/function.sprintf.php and here function vnsprintf( $format, array $data) http://php.net/manual/de/function.vsprintf.php where people wrote

How to construct WMI query

拈花ヽ惹草 提交于 2019-11-26 18:28:49
问题 I'd like to find results that Name starts with param1, and ends with param2 but my code doesn't work string wmiQuery = string.Format("SELECT CommandLine FROM Win32_Process WHERE Name LIKE '{0}%' AND Name LIKE '%{1}'", param1, param2); ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery); ManagementObjectCollection retObjectCollection = searcher.Get(); What's wrong? For comparision string wmiQuery = string.Format("SELECT CommandLine FROM Win32_Process WHERE Name LIKE '{0}

Is it better practice to use String.format over string Concatenation in Java?

為{幸葍}努か 提交于 2019-11-26 18:10:23
Is there a perceptible difference between using String.format and String concatenation in Java? I tend to use String.format but occasionally will slip and use a concatenation. I was wondering if one was better than the other. The way I see it, String.format gives you more power in "formatting" the string; and concatenation means you don't have to worry about accidentally putting in an extra %s or missing one out. String.format is also shorter. Which one is more readable depends on how your head works. workmad3 I'd suggest that it is better practice to use String.format() . The main reason is

Is it better practice to use String.format over string Concatenation in Java?

我是研究僧i 提交于 2019-11-26 17:26:34
问题 Is there a perceptible difference between using String.format and String concatenation in Java? I tend to use String.format but occasionally will slip and use a concatenation. I was wondering if one was better than the other. The way I see it, String.format gives you more power in "formatting" the string; and concatenation means you don't have to worry about accidentally putting in an extra %s or missing one out. String.format is also shorter. Which one is more readable depends on how your

Is String.Format as efficient as StringBuilder

孤者浪人 提交于 2019-11-26 16:00:56
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new StringBuilder(); string cat = "cat"; sb.Append("the ").Append(cat).(" in the hat"); string s = sb.ToString(); would that be as efficient or any more efficient as having: string cat = "cat"; string s = String.Format("The {0} in the hat", cat); If so, why? EDIT After some interesting answers, I realised I probably should have been a little clearer in what I was asking. I wasn't so much asking for which was quicker at concatenating a string, but which is quicker at injecting one string into another. In both cases above I

Format decimal for percentage values?

本秂侑毒 提交于 2019-11-26 09:19:30
问题 What I want is something like this: String.Format(\"Value: {0:%%}.\", 0.8526) Where %% is that format provider or whatever I am looking for. Should result: Value: %85.26. . I basically need it for wpf binding, but first let\'s solve the general formatting issue: <TextBlock Text=\"{Binding Percent, StringFormat=%%}\" /> 回答1: Use the P format string. This will vary by culture: String.Format("Value: {0:P2}.", 0.8526) // formats as 85.26 % (varies by culture) 回答2: If you have a good reason to set

Is String.Format as efficient as StringBuilder

柔情痞子 提交于 2019-11-26 04:40:16
问题 Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new StringBuilder(); string cat = \"cat\"; sb.Append(\"the \").Append(cat).(\" in the hat\"); string s = sb.ToString(); would that be as efficient or any more efficient as having: string cat = \"cat\"; string s = String.Format(\"The {0} in the hat\", cat); If so, why? EDIT After some interesting answers, I realised I probably should have been a little clearer in what I was asking. I wasn\'t so much asking for which was

Equivalent of String.format in jQuery

余生颓废 提交于 2019-11-26 00:39:32
问题 I\'m trying to move some JavaScript code from MicrosoftAjax to JQuery. I use the JavaScript equivalents in MicrosoftAjax of the popular .net methods, e.g. String.format(), String.startsWith(), etc. Are there equivalents to them in jQuery? 回答1: The source code for ASP.NET AJAX is available for your reference, so you can pick through it and include the parts you want to continue using into a separate JS file. Or, you can port them to jQuery. Here is the format function... String.format =

String output: format or concat in C#?

三世轮回 提交于 2019-11-25 23:31:18
问题 Let\'s say that you want to output or concat strings. Which of the following styles do you prefer? var p = new { FirstName = \"Bill\", LastName = \"Gates\" }; Console.WriteLine(\"{0} {1}\", p.FirstName, p.LastName); Console.WriteLine(p.FirstName + \" \" + p.LastName); Do you rather use format or do you simply concat strings? What is your favorite? Is one of these hurting your eyes? Do you have any rational arguments to use one and not the other? I\'d go for the second one. 回答1: Try this code.