TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 05-09-2007, 03:32 PM   #1
Peter Hartlén
Guest
 
Posts: n/a
VS2005 Resource Editor - How to make new line from string resource?

I understand that the\n and \r only means something to the C# compiler so
when retrieving a line like "Hello\r\nWorld" from a resource file (localized
form or self made resource file), it prints the text as just like it was
written.

Is there any easy way to introduce a newline (tab etc.) into a string
retrieved from a resource file? Or should I create a resource string for
each line?

Thanks,

Peter


  Reply With Quote
Old 05-09-2007, 03:32 PM   #2
Michael Nemtsev
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

Hello Peter,

Why not just read it into the string Properties.Resources.<your_resource>
and then add the new lines ?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


PH> I understand that the\n and \r only means something to the C#
PH> compiler so when retrieving a line like "Hello\r\nWorld" from a
PH> resource file (localized form or self made resource file), it prints
PH> the text as just like it was written.
PH>
PH> Is there any easy way to introduce a newline (tab etc.) into a
PH> string retrieved from a resource file? Or should I create a resource
PH> string for each line?
PH>
PH> Thanks,
PH>
PH> Peter
PH>


  Reply With Quote
Old 05-09-2007, 03:32 PM   #3
Peter Hartlen
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

> Why not just read it into the string Properties.Resources.<your_resource>
> and then add the new lines ?


Hmm, I'm not sure I follow...

I have a resource file with the following tag and text:
MsgHelloWorld "Hello\r\nWorld"

I then retrieve the resource with a resource manager like this:
resMan = new ResourceManager( ... )
string msg = resMan.GetString("MsgHelloWorld");
MessageBox.Show(msg);

This will print "Hello\r\nWorld", but I want it to print:
"Hello
World"

How did you mean I could solve this?

/ Peter


> PH> I understand that the\n and \r only means something to the C#
> PH> compiler so when retrieving a line like "Hello\r\nWorld" from a
> PH> resource file (localized form or self made resource file), it prints
> PH> the text as just like it was written.
> PH> PH> Is there any easy way to introduce a newline (tab etc.) into a
> PH> string retrieved from a resource file? Or should I create a resource
> PH> string for each line?
> PH> PH> Thanks,
> PH> PH> Peter
> PH>
>



  Reply With Quote
Old 05-09-2007, 03:32 PM   #4
Michael Nemtsev
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

Hello Peter,

hmmmmm, interesting.
seems that smth wrong with the text encoding. need to investigate

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


>> Why not just read it into the string
>> Properties.Resources.<your_resource> and then add the new lines ?
>>

PH> Hmm, I'm not sure I follow...
PH>
PH> I have a resource file with the following tag and text:
PH> MsgHelloWorld "Hello\r\nWorld"
PH>
PH> I then retrieve the resource with a resource manager like this:
PH> resMan = new ResourceManager( ... )
PH> string msg = resMan.GetString("MsgHelloWorld");
PH> MessageBox.Show(msg);
PH> This will print "Hello\r\nWorld", but I want it to print:
PH> "Hello
PH> World"
PH> How did you mean I could solve this?
PH>
PH> / Peter
PH>
>> PH> I understand that the\n and \r only means something to the C#
>> PH> compiler so when retrieving a line like "Hello\r\nWorld" from a
>> PH> resource file (localized form or self made resource file), it
>> prints
>> PH> the text as just like it was written.
>> PH> PH> Is there any easy way to introduce a newline (tab etc.) into
>> a
>> PH> string retrieved from a resource file? Or should I create a
>> resource
>> PH> string for each line?
>> PH> PH> Thanks,
>> PH> PH> Peter
>> PH>



  Reply With Quote
Old 05-09-2007, 03:32 PM   #5
Michael Nemtsev
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

Hello Michael,

ahh, damn, almost forgot, it's old trick.
when u read from the resources, you lost your escape sequece. u need to restore
it. changing \\r on \r

the following code fix it

string str = Properties.Resources.MsgHelloWorld;
str = str.Replace("\\n", "\n");
str = str.Replace("\\r", "\r");

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


MN> Hello Peter,
MN>
MN> hmmmmm, interesting.
MN> seems that smth wrong with the text encoding. need to investigate
MN> ---
MN> WBR,
MN> Michael Nemtsev [.NET/C# MVP] :: blog:
MN> http://spaces.live.com/laflour
MN> "The greatest danger for most of us is not that our aim is too high
MN> and we miss it, but that it is too low and we reach it" (c)
MN> Michelangelo
MN>
>>> Why not just read it into the string
>>> Properties.Resources.<your_resource> and then add the new lines ?

PH>> Hmm, I'm not sure I follow...
PH>>
PH>> I have a resource file with the following tag and text:
PH>> MsgHelloWorld "Hello\r\nWorld"
PH>>
PH>> I then retrieve the resource with a resource manager like this:
PH>> resMan = new ResourceManager( ... )
PH>> string msg = resMan.GetString("MsgHelloWorld");
PH>> MessageBox.Show(msg);
PH>> This will print "Hello\r\nWorld", but I want it to print:
PH>> "Hello
PH>> World"
PH>> How did you mean I could solve this?
PH>> / Peter
PH>>
>>> PH> I understand that the\n and \r only means something to the C#
>>> PH> compiler so when retrieving a line like "Hello\r\nWorld" from a
>>> PH> resource file (localized form or self made resource file), it
>>> prints
>>> PH> the text as just like it was written.
>>> PH> PH> Is there any easy way to introduce a newline (tab etc.) into
>>> a
>>> PH> string retrieved from a resource file? Or should I create a
>>> resource
>>> PH> string for each line?
>>> PH> PH> Thanks,
>>> PH> PH> Peter
>>> PH>



  Reply With Quote
Old 05-09-2007, 03:33 PM   #6
Willy Denoyette [MVP]
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

"Peter Hartlen" <peter@data.se> wrote in message
news:eA%239mkx6HHA.2208@TK2MSFTNGP06.phx.gbl...
>> Why not just read it into the string Properties.Resources.<your_resource>
>> and then add the new lines ?

>
> Hmm, I'm not sure I follow...
>
> I have a resource file with the following tag and text:
> MsgHelloWorld "Hello\r\nWorld"
>
> I then retrieve the resource with a resource manager like this:
> resMan = new ResourceManager( ... )
> string msg = resMan.GetString("MsgHelloWorld");
> MessageBox.Show(msg);
>
> This will print "Hello\r\nWorld", but I want it to print:
> "Hello
> World"
>
> How did you mean I could solve this?
>


MsgHelloWorld "Hello{0}World"
....

string msg = String.Format(resMan.GetString("MsgHelloWorld"),
Environment.NewLine));

Willy.



  Reply With Quote
Old 05-09-2007, 03:35 PM   #7
Grant Frisken
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

On Aug 31, 1:19 am, "Peter Hartlen" <pe...@data.se> wrote:
> > Why not just read it into the string Properties.Resources.<your_resource>
> > and then add the new lines ?

>
> Hmm, I'm not sure I follow...
>
> I have a resource file with the following tag and text:
> MsgHelloWorld "Hello\r\nWorld"
>
> I then retrieve the resource with a resource manager like this:
> resMan = new ResourceManager( ... )
> string msg = resMan.GetString("MsgHelloWorld");
> MessageBox.Show(msg);
>
> This will print "Hello\r\nWorld", but I want it to print:
> "Hello
> World"
>


You really shouldn't add the new lines programmatically - because when
you come to localize your application to another language you may want
to have the line breaks in different positions. The best way is to
include the new lines in your actual resources. You can do this in
one of two ways:

1. Open the resx file in the VS designer and use Shift+Enter when you
want want a line break. You will need to resize the row using the
grab bars to make it big enough to see multiple lines.

2. Open the resx file as code and add the line breaks directly in the
XML.

The Visual Studio Resource editor really is fairly basic and quite
irritating to use for large amounts of text when localizing so you
could also consider using a tool like our Globalizer.NET that allows
you to see and edit all your resources (for all languages) in a single
easy to edit form (see http://www.infralution.com/globalizer.html).

Regards
Grant Frisken
Infralution
www.infralution.com

Globalizer.NET - makes localizing .NET Application easy

  Reply With Quote
Old 05-09-2007, 03:36 PM   #8
Peter Hartlen
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

> ahh, damn, almost forgot, it's old trick. when u read from the resources,
> you lost your escape sequece. u need to restore it. changing \\r on \r
>
> the following code fix it
>
> string str = Properties.Resources.MsgHelloWorld;
> str = str.Replace("\\n", "\n");
> str = str.Replace("\\r", "\r");
>


Hello Michael, thanks for your reply.

Using this technique I assume you could use any "unique character set" to
represent the various escape sequences. So I could write something like this
in my resource file:

"HelloBlaBlaWorld" and then use

str = str.Replace("BlaBla","\n");

However, I'm not really fond of this solution, as it could come to a
situation where a string is "newlined" in one language and not in another
language. Also it provides a rather large amount of extra code...

Regards,

Peter


  Reply With Quote
Old 05-09-2007, 03:36 PM   #9
Peter Hartlén
Guest
 
Posts: n/a
Re: VS2005 Resource Editor - How to make new line from string resource?

> You really shouldn't add the new lines programmatically - because when
> you come to localize your application to another language you may want
> to have the line breaks in different positions. The best way is to
> include the new lines in your actual resources. You can do this in
> one of two ways:
>
> 1. Open the resx file in the VS designer and use Shift+Enter when you
> want want a line break. You will need to resize the row using the
> grab bars to make it big enough to see multiple lines.


Perfect! Thanks!

/ Peter


  Reply With Quote
Old 08-04-2008, 03:37 PM   #10
Newbie
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 podganca is an unknown quantity at this point
Re: VS2005 Resource Editor - How to make new line from string resource?

In Resource editor Press Shit+Enter instead \n
podganca is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Change the Default Icon of an Exe using Resource Editor / Resource Hacker? Strider TIPS 'n' TRICKS 4 21-02-2008 01:34 PM
help with resource hacker shields Software Troubleshooting 1 15-10-2007 05:18 PM
Office 2007 Resource Kit Tom B Microsoft Office 2 28-08-2007 02:22 PM
The Big Ol' Ubuntu Security Resource Jose Manuel Tella Llop Windows XP 0 16-08-2007 02:34 PM
A good OS resource center sree Tech Reference 0 13-06-2006 11:47 PM

Google
 


All times are GMT +5.5. The time now is 05:17 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional