473,386 Members | 1,699 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,386 software developers and data experts.

String wierdness...

I send out a daily email to technicians regarding nightly backup logs. I
use the following code to generate the body of the email:

tmpBody += vbCrLf
tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
monitored) -----"
tmpBody += vbCrLf
tmpBody += <Specific Server Error Message>

However, I get emails that sometimes have the linebreak before the
Specific Server Error Message, and some that don't. Here's a sample
email:

----- npl2bjl (1 servers monitored) ----- NEOMASVR0000 (Daily Backup):
Canceled by NEOMASVR0000\US\R05D53BESvc,Error - Mount failed. User
canceled a Physical Volume Library operation.

Why is there no linebreak between "-----" and "NEOMASVR0000"? When I
look at the email in a hex editor, it's just a space. Some of the emails
look correct, such as:

----- neb1jwg (3 servers monitored) -----
NECOLSVR0005 (W Drive): Failed,Storage device "COMPAQ 1" reported an
error on a request to write data to media.Error reported:Data error
(cyclic redundancy check). Warning - A severe error occurred while
reading or writing data. This job may not have been successfully
completed.Robotic Library: Drive: COMPAQ 1Slot: A communications
failure has occurred between the Backup Exec job engine and the remote
agent.

Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Jun 2 '06 #1
9 1384
Not sure this will help with your problem, but I would rewrite your code like
this:

tmpBody = vbCrLf
tmpBody &= "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
monitored) -----"
tmpBody &= vbCrLf
tmpBody &= <Specific Server Error Message>

When dealing with Strings it's good practice to avoid "+" and use "&" instead
since the former is an arithmetic operator which can cause problems when there
are numbers in your string.

"Terry Olsen" <to******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP05.phx.gbl...
I send out a daily email to technicians regarding nightly backup logs. I
use the following code to generate the body of the email:

tmpBody += vbCrLf
tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
monitored) -----"
tmpBody += vbCrLf
tmpBody += <Specific Server Error Message>

However, I get emails that sometimes have the linebreak before the
Specific Server Error Message, and some that don't. Here's a sample
email:

----- npl2bjl (1 servers monitored) ----- NEOMASVR0000 (Daily Backup):
Canceled by NEOMASVR0000\US\R05D53BESvc,Error - Mount failed. User
canceled a Physical Volume Library operation.

Why is there no linebreak between "-----" and "NEOMASVR0000"? When I
look at the email in a hex editor, it's just a space. Some of the emails
look correct, such as:

----- neb1jwg (3 servers monitored) -----
NECOLSVR0005 (W Drive): Failed,Storage device "COMPAQ 1" reported an
error on a request to write data to media.Error reported:Data error
(cyclic redundancy check). Warning - A severe error occurred while
reading or writing data. This job may not have been successfully
completed.Robotic Library: Drive: COMPAQ 1Slot: A communications
failure has occurred between the Backup Exec job engine and the remote
agent.

Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***

Jun 2 '06 #2

"Terry Olsen" <to******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP05.phx.gbl...
I send out a daily email to technicians regarding nightly backup logs. I
use the following code to generate the body of the email:

tmpBody += vbCrLf
tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
monitored) -----"
tmpBody += vbCrLf
tmpBody += <Specific Server Error Message>

However, I get emails that sometimes have the linebreak before the
Specific Server Error Message, and some that don't. Here's a sample
email:


I would use String.Format :)

Const BODY_FORMAT As String = _
vbNewLine & "----- {0} ({1} server{2} monitored) -----" & _
vbNewLine & "{3}"

Dim tmpBody As String = String.Format( _
BODY_FORMAT, _
SupTechs.Item(j), _
tmpCount, _
IIf(tmpCount = 1, String.Empty, "s"), _
<specific server error message here> _
)

HTH :0

Mythran
Jun 2 '06 #3

"Terry Olsen" <to******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP05.phx.gbl...
I send out a daily email to technicians regarding nightly backup logs. I
use the following code to generate the body of the email:

tmpBody += vbCrLf
tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
monitored) -----"
tmpBody += vbCrLf
tmpBody += <Specific Server Error Message>

However, I get emails that sometimes have the linebreak before the
Specific Server Error Message, and some that don't. Here's a sample
email:

----- npl2bjl (1 servers monitored) ----- NEOMASVR0000 (Daily Backup):
Canceled by NEOMASVR0000\US\R05D53BESvc,Error - Mount failed. User
canceled a Physical Volume Library operation.

Why is there no linebreak between "-----" and "NEOMASVR0000"? When I
look at the email in a hex editor, it's just a space. Some of the emails
look correct, such as:

----- neb1jwg (3 servers monitored) -----
NECOLSVR0005 (W Drive): Failed,Storage device "COMPAQ 1" reported an
error on a request to write data to media.Error reported:Data error
(cyclic redundancy check). Warning - A severe error occurred while
reading or writing data. This job may not have been successfully
completed.Robotic Library: Drive: COMPAQ 1Slot: A communications
failure has occurred between the Backup Exec job engine and the remote
agent.

Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***


Oh, and I forgot to mention, it seems like your email viewer may be
translating the text as html, therefore removing carriage-returns and
linefeeds. Are you setting the body format type to text, specifically?

HTH again,
Mythran

Jun 2 '06 #4

"Terry Olsen" <to******@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP05.phx.gbl...
:I send out a daily email to technicians regarding nightly backup logs. I
: use the following code to generate the body of the email:
:
: tmpBody += vbCrLf
: tmpBody += "----- " & SupTechs.Item(j) & " (" & tmpCount & " servers
: monitored) -----"
: tmpBody += vbCrLf
: tmpBody += <Specific Server Error Message>
:
: However, I get emails that sometimes have the linebreak before the
: Specific Server Error Message, and some that don't. Here's a sample
: email:
:
: ----- npl2bjl (1 servers monitored) ----- NEOMASVR0000 (Daily Backup):
: Canceled by NEOMASVR0000\US\R05D53BESvc,Error - Mount failed. User
: canceled a Physical Volume Library operation.
:
: Why is there no linebreak between "-----" and "NEOMASVR0000"? When I
: look at the email in a hex editor, it's just a space. Some of the emails
: look correct, such as:
:
: ----- neb1jwg (3 servers monitored) -----
: NECOLSVR0005 (W Drive): Failed,Storage device "COMPAQ 1" reported an
: error on a request to write data to media.Error reported:Data error
: (cyclic redundancy check). Warning - A severe error occurred while
: reading or writing data. This job may not have been successfully
: completed.Robotic Library: Drive: COMPAQ 1Slot: A communications
: failure has occurred between the Backup Exec job engine and the remote
: agent.
:
: Any ideas?
:
: *** Sent via Developersdex http://www.developersdex.com ***
Does your mail reader strip what it considers "extra" line feeds?

Ralf
Jun 2 '06 #5
> Oh, and I forgot to mention, it seems like your email viewer may be
translating the text as html, therefore removing carriage-returns and
linefeeds. Are you setting the body format type to text, specifically?


Yes, I figured it out. Outlook was "removing extra linefeeds in plain-text
messages." I cleared that and everything looks fine. But I do appreciate
the pointers about the strings. Would a StringWriter or StringBuilder be a
better choice? For that matter, what's the difference between the two?
Jun 3 '06 #6
Terry,

The first thing to do is in my idea taking the advice of Mike Lowery.

With Option Strict of your code as now can give very unpredictable results.

Cor

"Terry Olsen" <to******@hotmail.com> schreef in bericht
news:Oj**************@TK2MSFTNGP05.phx.gbl...
Oh, and I forgot to mention, it seems like your email viewer may be
translating the text as html, therefore removing carriage-returns and
linefeeds. Are you setting the body format type to text, specifically?


Yes, I figured it out. Outlook was "removing extra linefeeds in
plain-text messages." I cleared that and everything looks fine. But I do
appreciate the pointers about the strings. Would a StringWriter or
StringBuilder be a better choice? For that matter, what's the difference
between the two?

Jun 3 '06 #7
Terry Olsen wrote:
Oh, and I forgot to mention, it seems like your email viewer may be
translating the text as html, therefore removing carriage-returns and
linefeeds. Are you setting the body format type to text, specifically?


Yes, I figured it out. Outlook was "removing extra linefeeds in plain-text
messages." I cleared that and everything looks fine. But I do appreciate
the pointers about the strings. Would a StringWriter or StringBuilder be a
better choice? For that matter, what's the difference between the two?


A StringBuilder would be the better choise.

A StringBuilder is used to put together a string without making new
copies of the string for each operation.

The += operator might give the impression that a string is added at the
end of an existing string, but that is not so. Strings in .NET are
immutable, e.g. they can not be changed. The += operator concatenates
the strings into a new string, and the reference to the new string
replaces the original string.

For a few short strings the += operator works fine, but the larger the
string grows, the more data has to be copied for each operation. You
should use a StringBuilder when there are more than a few strings, and
always if you don't know beforehand how many strings there will be.

A StringWriter is a TextWriter wrapper around a StringBuilder. One
specific advantage of the StringWriter is when you write different data
types to it. You can specify a culture when you create the StringWriter,
and that cuture is then used to convert things like numbers and dates to
strings when you write them to the StringWriter. When you do the same
using a StringBuilder, it always uses the default culture, or you have
to specify the culture for each value you add using the AppendFormat method.
Jun 3 '06 #8
Terry,

The Stringbuilder (a mutable string (collection) of char objects) would give
you in your problem probably not any advantage. For that are the strings to
short.

A stringwriter gives you the oppurtinity to write whatever to a string
instead of to a file or a stream.

http://www.vb-tips.com/default.aspx?...a-c891846eaf0b

I hope this gives some direct answers on your latest question.

Cor

"Terry Olsen" <to******@hotmail.com> schreef in bericht
news:Oj**************@TK2MSFTNGP05.phx.gbl...
Oh, and I forgot to mention, it seems like your email viewer may be
translating the text as html, therefore removing carriage-returns and
linefeeds. Are you setting the body format type to text, specifically?


Yes, I figured it out. Outlook was "removing extra linefeeds in
plain-text messages." I cleared that and everything looks fine. But I do
appreciate the pointers about the strings. Would a StringWriter or
StringBuilder be a better choice? For that matter, what's the difference
between the two?

Jun 3 '06 #9

"Terry Olsen" <to******@hotmail.com> wrote in message
news:Oj**************@TK2MSFTNGP05.phx.gbl...
: >
: > Oh, and I forgot to mention, it seems like your email viewer may be
: > translating the text as html, therefore removing carriage-returns and
: > linefeeds. Are you setting the body format type to text, specifically?
:
: Yes, I figured it out. Outlook was "removing extra linefeeds in
: plain-text messages." I cleared that and everything looks fine. But
: I do appreciate the pointers about the strings. Would a StringWriter
: or StringBuilder be a better choice? For that matter, what's the
: difference between the two?
It's my understanding string concatenation is fine as long as the number of
concatenation operations is small. I saw a graph once comparing times for
multiple concatenations using the two methods and with small concatentation
counts, the "&" was actually somewhat faster. It wasn't until the number of
concatenations hit around 25 (if I remember correctly) that the string
builder came into its own and then the difference from that point forward
was dramatic.
Ralf

--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Jun 3 '06 #10

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

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
13
by: Tek Boy | last post by:
I've been experiencing some (reproducable) wierdness when I try to generate some very basic HTML using ASP. Check out the following (basic) ASP code: ===========================================...
0
by: amber | last post by:
Hello, I'm having some wierdness with a report I've created in VB.NET (with Crysal Reports). The report is called repCPDocSubmissionSummary.vb I created it a while ago, and have been using it...
5
by: Eduardo Olivarez | last post by:
The following code does not work correctly on my machine. Either one of the scanf()'s alone work perfectly. However, when they are combined, the second scanf() call just reads what the first one...
9
by: Bobby Edward | last post by:
Are there any add-ons to Visual Studio 2008 that will help me troubleshoot CSS wierdness? Like showing the padding/margin with difference colors, etc...? I'm trying to figure out some wierd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.