473,414 Members | 1,636 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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
Aug 30 '07 #1
9 9343
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
PHI understand that the\n and \r only means something to the C#
PHcompiler so when retrieving a line like "Hello\r\nWorld" from a
PHresource file (localized form or self made resource file), it prints
PHthe text as just like it was written.
PH>
PHIs there any easy way to introduce a newline (tab etc.) into a
PHstring retrieved from a resource file? Or should I create a resource
PHstring for each line?
PH>
PHThanks,
PH>
PHPeter
PH>
Aug 30 '07 #2
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

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

Aug 30 '07 #3
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_resourceand then add the new lines ?
PHHmm, I'm not sure I follow...
PH>
PHI have a resource file with the following tag and text:
PHMsgHelloWorld "Hello\r\nWorld"
PH>
PHI then retrieve the resource with a resource manager like this:
PHresMan = new ResourceManager( ... )
PHstring msg = resMan.GetString("MsgHelloWorld");
PHMessageBox.Show(msg);
PHThis will print "Hello\r\nWorld", but I want it to print:
PH"Hello
PHWorld"
PHHow did you mean I could solve this?
PH>
PH/ Peter
PH>
>PHI understand that the\n and \r only means something to the C#
PHcompiler so when retrieving a line like "Hello\r\nWorld" from a
PHresource file (localized form or self made resource file), it
prints
PHthe text as just like it was written.
PHPHIs there any easy way to introduce a newline (tab etc.) into
a
PHstring retrieved from a resource file? Or should I create a
resource
PHstring for each line?
PHPHThanks,
PHPHPeter
PH>

Aug 30 '07 #4
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
MNHello Peter,
MN>
MNhmmmmm, interesting.
MNseems that smth wrong with the text encoding. need to investigate
MN---
MNWBR,
MNMichael Nemtsev [.NET/C# MVP] :: blog:
MNhttp://spaces.live.com/laflour
MN"The greatest danger for most of us is not that our aim is too high
MNand we miss it, but that it is too low and we reach it" (c)
MNMichelangelo
MN>
>>Why not just read it into the string
Properties.Resources.<your_resourceand 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>>
>>PHI understand that the\n and \r only means something to the C#
PHcompiler so when retrieving a line like "Hello\r\nWorld" from a
PHresource file (localized form or self made resource file), it
prints
PHthe text as just like it was written.
PHPHIs there any easy way to introduce a newline (tab etc.) into
a
PHstring retrieved from a resource file? Or should I create a
resource
PHstring for each line?
PHPHThanks,
PHPHPeter
PH>

Aug 30 '07 #5
"Peter Hartlen" <pe***@data.sewrote in message
news:eA****************@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.

Aug 30 '07 #6
On Aug 31, 1:19 am, "Peter Hartlen" <pe...@data.sewrote:
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

Aug 31 '07 #7
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
Aug 31 '07 #8
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
Aug 31 '07 #9
Dim resReader As ResourceReader = Nothing
Dim dicEnumerator As IDictionaryEnumerator = Nothing
Dim keyValuePair As StringBuilder

resReader = New ResourceReader(path)
dicEnumerator = resReader.GetEnumerator()

While dicEnumerator.MoveNext()
'Environment.NewLine is the new line char most appropriate for the 'environment
keyValuePair.Append(dicEnumerator.Key + "=" + dicEnumerator.Value.ToString().Replace("\n", Environment.NewLine))
End While

As you can see that we have replaced \n coming as part of resource string by Environment.NewLine. Similar approach will work in C#.

Regards,
Deepankar
Jul 21 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Danny Pressley | last post by:
I have a VS.NET 2003 Visual C++ MFC Application Project in which I added a new resource file, I then added an icon to this new resource file and did a rebuild and got the following error: "fatal...
5
by: Adam Parkin | last post by:
Hello all, I am seeking some help with the following problem. I'm working on an application where I have a resource file, and in this resource file what I want to store is a list of file names...
4
by: | last post by:
When do they plan on making this essential utility USEFUL? In its current form its pointless. How could they let this out? Its useless.
16
by: CMM | last post by:
Is it me or has anyone noticed that F1 is really dumb in VS2005. Since VB3 I have been able to click F1 on an ambiguous method in code and the IDE automatically determines the type based on the...
11
by: CMM | last post by:
I am so disappointed in VS2005. The "little things" wrong with it are just mind-boggling. Boy, I'll be so mad if I have to wait a year for the ".1" release that fixes all the bugs in this obvious...
1
by: n4ixt | last post by:
I have two macros I used to use in VS 2003. I recently tried to import them for use in VS 2005, but they don't seem to work. I open the macro explorer, right click and do run, but it's like VS...
0
by: GT | last post by:
This question has been posted before, but without any response so therefore I'm trying once more. I'm trying to embed .resource files into a Windows application in VS2005, and then compile and...
21
by: Peter Bradley | last post by:
Hi all, This post is sort of tangentially related to my earlier posts on configuration files for DLLs. Does anyone know how to create typed DataSets using VS2005's new DataSet designer, but...
0
by: Randy Gault | last post by:
I've created a very simple user control (just a label and a textbox). They are in their own assembly. Now I want to add a property to that control, so that when I add that control into a form in...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.