Hello, I am trying to write a regular expression to match and split a custom variable syntax in C#. The idea here is a custom formatting of string values very similar to the .NET String.Format/{0} style of string formatting.
For example the user would define a String format to be evaluated at runtime like so:
D:\Path\{LanguageId}\{Pers...
For instance:
String login = String.Format("computer={0}&ver={1}.{2}.{3}&from={4}&realcomputername={5}&type={6}&Channels={7}&Hotkeys={8}&ID={9}\r\n",
serviceConfig.Computer,
serviceConfig.Version.Major,
serviceConfig.Version.Minor,
serviceConfig.Version.Build,
userName,
...
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=%%}" />
...
For instance, let's say I have the DateTime format-string in a string variable, is there any syntax or method in .NET that would let me do the equivalent of this invalid code:
String line = String.Format("{0:{1}}", DateTime.Now, dateTimeFormat);
^^^ ^
...
So I have a client who does not allow any server side coding, except in rare occurences classic asp, so everything is HTML and javascript.
So basically I need to build a URL from the form and then redirect. Javascript isn't necessarily my thing, but this would take me 5 minutes in asp.net using String.Format.
Is there a String.Forma...
How do I stick HTML formatting into a String object in C#?
Here's what I have:
c.DepartmentAbbr.ToString() + " - (" + c.DepartmentName.ToString() + ")"
where c.DepartmentAbbr.ToString() and c.DepartmentName.ToString() are both fields being selected from a data context using LINQ.
Here's what I essentially want:
"<b>" + c.Department...
For instance, "%11.2lf" in C++ becomes "%11.2f" in Java.
How about for long format?
...
Is there any way to check the format string at compile time ?
Example:
Console.WriteLine("{0} is a really {1} site", "stackoverflow.com", "cool");//this will run
//this will give an exception as only one argument is supplied
Console.WriteLine("{0} is a really {1} site", "stackoverflow.com");
Exception:"Index (zero based) must b...
I am using a DataBinder.Eval expression in an ASP.NET Datagrid, but I think this question applies to String formatting in .NET in general. The customer has requested that if the value of a string is 0, it should not be displayed. I have the following hack to accomplish this:
<%# IIf(DataBinder.Eval(Container.DataItem, "MSDWhole").Trim...
I have this piece of code in c#:
private static void _constructRow(SqlDataReader reader, system.IO.StreamWriter stwr, bool getColumnName)
{
for (int i = 0; i < reader.FieldCount; i++)
stwr.Writeline(String.Format("<td>{0}</td"), getColumnName ? reader.GetName(i) : reader.GetValue(i).ToString()));
}
I'm trying to understand what t...
What is the best way to get formatted Int32 numbers?
Let say I have this o function:
string o(int x);
This is the value that o need to return according to x
x = 0 => o = 00
x = 1 => o = 01
x = 5 => o = 05
x = 10 => o = 10
x = 31 => o = 31
x = 106 => o = 106
...
Per the documentation, String.Format will throw a FormatException if either (A) the format string is invalid or (B) the format string contains an index that cannot be found in the args array.
I want to be able to determine which (if either) of those conditions fail on any arbitrary string and array of arguments.
Is there anything that ...
I am sure this is a simple question for you guys but I don't know what this developer is doing.
name = String.Format(MyStringBuilder + "");
If I convert this to VB I get the message "operator + is not defined for types system.text.stringbuilder and string". Same thing if I use &.
...
I have this function. The visual studio profile marked the line with string.Format as hot and were i spend much of my time.
How can i write this loop more efficiently?
public string EscapeNoPredicate(string sz)
{
var s = new StringBuilder(sz);
s.Replace(sepStr, sepStr + sepStr);
foreach (char v in Illeg...
I often use String.Format() because it makes the building of strings more readable and manageable.
Is there anyway to reduce its syntactical verbosity, e.g. with an extension method, etc.?
Logger.LogEntry(String.Format("text '{0}' registered", pair.IdCode));
public static void LogEntry(string message)
{
...
}
e.g. I would like t...
I was using Reflector to look at the implementation of String.Format and had always been under the impression that the overloads of String.Format that took 1, 2 & 3 arguments were optimized versions of the method that takes an object array. However, what I found was that internally they create an object array and then call a method that ...
There is a bug in MicrosoftAjax.js String.format function when using Chrome 5.0.375. The function randomly returns 'undefined' for some dates.
I went around that by using jquery date formatter that comes with datepicker.
...
I am trying to display a number, stored in a dataset as a string, as a phone number. I have a label that Binds to a value but doesn't display the format that I passed as an arg:
<asp:Label ID="lbl005108002" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "phone number", "{0:(###) ###-####}") %>'></asp:Label>
As a test I t...
Hi,
I'm trying to use an arraylist as the parameter to String.Format.
msg = msg & String.Format("<td>{0}</td>" & _
"<td>{1}</td>" & _
"<td>{2}</td>" & _
"<td>{3}</td>" & _
...
I found the following C++ code (comments added myself):
// frame_name is a char array
// prefix is std::string
// k is a for loop counter
// frames is a std::vector string
sprintf(frameName, "%s_%0*s.bmp", prefix.c_str(), k, frames[k].c_str());
I then try to translate it to C#
// prefix is string
// k is a for loop counter
// frames ...