-
Use resouce string as format string
I have the following codes:
ResourceManager rm;
String sF;
...
// Use resource string as format
sF = rm.GetString("101"); // "Name: {0}\tWeight: {1}"
Console.WriteLine( sF ); // Name: {0}\tWeight: {1}
Console.WriteLine( sF, "Peter", 180 ); // Name: Peter\tWeight: 180
// Use string variable as format
sF = "Name: {0}\tWeight: {1}";
Console.WriteLine( sF ); // Name: {0} Weight: {1}
Console.WriteLine( sF, "Peter", 180 ); // Name: Peter Weight: 180
The problem is that \t in format string from resource does not work the
same way as in a string variable or constant (as expected as a tab).
Why?
D. Chu
-
Re: Use resouce string as format string
When you enter \t in the editor, the compiler replaces that with the
actual tab character in the string. When the resource string contains \t,
it simply contains the two characters '\' and 't'. I don't know how to
get a tab into the resource, though. I haven't looked at resources yet.
perhaps?
--
Rune Bivrin
- OOP since 1989
- SQL Server since 1990
- VB since 1991
"David Chu" <chud@hotmail.com> wrote in news:3e1c7714$2
@tnews.web.devx.com:
>
> I have the following codes:
>
> ResourceManager rm;
> String sF;
> ...
> // Use resource string as format
> sF = rm.GetString("101"); // "Name: {0}\tWeight: {1}"
> Console.WriteLine( sF ); // Name: {0}\tWeight: {1}
> Console.WriteLine( sF, "Peter", 180 ); // Name: Peter\tWeight: 180
> // Use string variable as format
> sF = "Name: {0}\tWeight: {1}";
> Console.WriteLine( sF ); // Name: {0} Weight: {1}
> Console.WriteLine( sF, "Peter", 180 ); // Name: Peter Weight: 180
>
> The problem is that \t in format string from resource does not work the
> same way as in a string variable or constant (as expected as a tab).
>
> Why?
>
> D. Chu
>
-
Re: Use resouce string as format string
Rune Bivrin,
You are right. '\t' in a string in source code is interpreted to a tab code,
however, '\t' in a string retrieved from resouce is '\' and 't'. If you compare
the lenghth of two string, you can find it out.
I remembered that in VB6.0 the newline code has to be none-ascii code '\0'
in a string and it cannot be added directly to resouce file by VB's resouce
editor. What I did is by using other editor to paste the none-ascii code
to the resouce file then to compile it. Maybe it is the same case for C#'s
resouce file (none-ascii codes like tab, newline have to be hard-coded to
resouce file through other editors).
D. Chu
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks