473,772 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert VB.Net code to C# code, the results are different in debug mode

The piece of code is for a Web Form Page. Who can tell me why? Thanks a lot!
------------------------------------------------
VB.Net Code:
Protected Overrides Sub AddParsedSubObj ect(ByVal obj As Object)

If (TypeOf obj Is LiteralControl) Then

Dim lc As LiteralControl = obj

Dim text As String = lc.Text.ToLower ()

Result:

text: text "
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>home</title>
<meta name="generator " content="micros oft visual studio .net 7.1">
<meta name="code_lang uage" content="visual basic .net 7.1">
<meta name="vs_defaul tclientscript" content="javasc ript">
<meta name="vs_target schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</head>
<body ms_positioning= "gridlayout ">

--------------------------

C# Code:

protected override void AddParsedSubObj ect(object obj)

{

if(obj is LiteralControl) {

LiteralControl lc = (LiteralControl ) obj;

String text = lc.Text.ToLower ();

Result:

text "\r\n<!doct ype html public \"-//w3c//dtd html 4.0 transitional//en\"
\r\n<html>\r\n \t<head>\r\n\t\ t<title>commerc e</title>\r\n\t\t< meta

name=\"generato r\" content=\"micro soft visual studio .net
7.1\">\r\n\t\t< meta name=\"code_lan guage\" content=\"c#\"> \r\n\t\t<meta
name=\"vs_defau ltclientscript\ " content=\"javas cript\">\r\n\t\ t<meta
name=\"vs_targe tschema\"
content=\"http://schemas.microso ft.com/intellisense/ie5\">\r\n\t</head>\r\n\t<bod y
ms_positioning= \"gridlayout \">
Nov 16 '05 #1
2 3627
The reason for this is that VB.NET *protects* the developer from literal
strings by automagically parsing it and changing things like line feeds,
tabs, double-quotes, etc to their respective ASCII codes and then stores
them that way (AFAIK).

C# does not do this. (In C (Java, C++, C#, etc) based languages, things like
double quotes have to be escaped, much as you have seen in your code
output: --><meta name=\"generato r\" content=\"micro soft visual studio
..net\"><--)

For instance, when you create a string using the line:
"The "quick" brown dog
jumped over the lazy fox."

VB.NET will parse it and convert all the \r\n (typical windows linefeed) and
double quotes for you. C# on the other hand will parse it as "The \"quick\"
brown dog\r\njumped over the lazy fox". This is because C# reads the string
literally.

HTH,
~d

"name" <li********@sym patico.ca> wrote in message
news:un******** ************@ne ws20.bellglobal .com...
The piece of code is for a Web Form Page. Who can tell me why? Thanks a
lot!
------------------------------------------------
VB.Net Code:
Protected Overrides Sub AddParsedSubObj ect(ByVal obj As Object)

If (TypeOf obj Is LiteralControl) Then

Dim lc As LiteralControl = obj

Dim text As String = lc.Text.ToLower ()

Result:

text: text "
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>home</title>
<meta name="generator " content="micros oft visual studio .net 7.1">
<meta name="code_lang uage" content="visual basic .net 7.1">
<meta name="vs_defaul tclientscript" content="javasc ript">
<meta name="vs_target schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</head>
<body ms_positioning= "gridlayout ">

--------------------------

C# Code:

protected override void AddParsedSubObj ect(object obj)

{

if(obj is LiteralControl) {

LiteralControl lc = (LiteralControl ) obj;

String text = lc.Text.ToLower ();

Result:

text "\r\n<!doct ype html public \"-//w3c//dtd html 4.0 transitional//en\"
\r\n<html>\r\n \t<head>\r\n\t\ t<title>commerc e</title>\r\n\t\t< meta

name=\"generato r\" content=\"micro soft visual studio .net
7.1\">\r\n\t\t< meta name=\"code_lan guage\" content=\"c#\"> \r\n\t\t<meta
name=\"vs_defau ltclientscript\ " content=\"javas cript\">\r\n\t\ t<meta
name=\"vs_targe tschema\"
content=\"http://schemas.microso ft.com/intellisense/ie5\">\r\n\t</head>\r\n\t<bod y
ms_positioning= \"gridlayout \">

Nov 16 '05 #2
Great, Thanks!
"DotNet Coder" <d0*********@ya hoo.com> wrote in message
news:eH******** ******@TK2MSFTN GP12.phx.gbl...
The reason for this is that VB.NET *protects* the developer from literal
strings by automagically parsing it and changing things like line feeds,
tabs, double-quotes, etc to their respective ASCII codes and then stores
them that way (AFAIK).

C# does not do this. (In C (Java, C++, C#, etc) based languages, things
like double quotes have to be escaped, much as you have seen in your code
output: --><meta name=\"generato r\" content=\"micro soft visual studio
.net\"><--)

For instance, when you create a string using the line:
"The "quick" brown dog
jumped over the lazy fox."

VB.NET will parse it and convert all the \r\n (typical windows linefeed)
and double quotes for you. C# on the other hand will parse it as "The
\"quick\" brown dog\r\njumped over the lazy fox". This is because C# reads
the string literally.

HTH,
~d

"name" <li********@sym patico.ca> wrote in message
news:un******** ************@ne ws20.bellglobal .com...
The piece of code is for a Web Form Page. Who can tell me why? Thanks a
lot!
------------------------------------------------
VB.Net Code:
Protected Overrides Sub AddParsedSubObj ect(ByVal obj As Object)

If (TypeOf obj Is LiteralControl) Then

Dim lc As LiteralControl = obj

Dim text As String = lc.Text.ToLower ()

Result:

text: text "
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>home</title>
<meta name="generator " content="micros oft visual studio .net 7.1">
<meta name="code_lang uage" content="visual basic .net 7.1">
<meta name="vs_defaul tclientscript" content="javasc ript">
<meta name="vs_target schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</head>
<body ms_positioning= "gridlayout ">

--------------------------

C# Code:

protected override void AddParsedSubObj ect(object obj)

{

if(obj is LiteralControl) {

LiteralControl lc = (LiteralControl ) obj;

String text = lc.Text.ToLower ();

Result:

text "\r\n<!doct ype html public \"-//w3c//dtd html 4.0 transitional//en\"
>\r\n<html>\r\n \t<head>\r\n\t\ t<title>commerc e</title>\r\n\t\t< meta

name=\"generato r\" content=\"micro soft visual studio .net
7.1\">\r\n\t\t< meta name=\"code_lan guage\" content=\"c#\"> \r\n\t\t<meta
name=\"vs_defau ltclientscript\ " content=\"javas cript\">\r\n\t\ t<meta
name=\"vs_targe tschema\"
content=\"http://schemas.microso ft.com/intellisense/ie5\">\r\n\t</head>\r\n\t<bod y
ms_positioning= \"gridlayout \">


Nov 16 '05 #3

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

Similar topics

16
2427
by: John Smith | last post by:
Lets say you have a function "debug printf" which works like printf but will get left out if _DEBUG flag is not defined along with the strings which are to be printed. Now I defined this: #ifdef _DEBUG void dbgprintf(char *szFormat, ...); #else #define dbgprintf
16
16429
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
9
2454
by: GRoll21 | last post by:
I have a program here that asks the number of students surveyed. then it will ask how many movies each student has watched. After thats been collected it does functions to find the average, median, and mode. The problem I am having is getting it to return the mode. I have a function set up but I'm not sure if it will correctly return the mode. I am getting 1 error. c:\C++\math\math.cpp(49): error C2664: 'getMode' : cannot convert...
7
3433
by: Randy Yates | last post by:
Hi, I work in an embedded environment in which we often use a mix of C and assembly code. Thus a recurring requirement is to be able to take a C header file with structure definitions as input and create an assembly include file with the structure member offsets defined. The problem is that the structure offsets are a complicated function of other syntactic elements such as other structures (I could have a structure as a member of...
7
21363
by: Wysiwyg | last post by:
Is there any way besides adding a specific debug command line argument for the project to tell if an application is running in debug mode? Thanks! Bill
2
3958
by: Scott Yost | last post by:
I reference a .NET DLL to import some of my custom types. I can build that DLL in debug or release mode, but I usually keep the debug one built so I can debug it. When I want to link to the release version of the DLL, I find that I have to remove the reference from the project and point VS. NET to the release version of the DLL. Is there some way to do this automatically, like it usually done in the past, so that the release/debug switch...
21
2858
by: Chris Durkin | last post by:
I've got an ASP.NET website on my local box, set to compile to bin\Debug and bin\Release in debug and release modes. Both directories are populated with dlls, as the solution has been compiled in both modes. When I browse to the local website, it works, but which set of dlls is it using? What happens when I deploy to Test and there is only a \bin\ directory, no \Debug or \Release? I assume .NET has some path-searching rules that govern...
6
5910
by: bantamweight | last post by:
Hi, I create a project with vs2005 (both c++ and c# are used, sames the problem is about c++) and it working well in Debug version but the result is wrong in Release version. I checked again and again and no difference of logic is found between two versions. I'm confused and don't known how to correct it. Is there anyone encountered similar deed? Any tips is wellcome. Regards.
12
1605
by: colin | last post by:
Hi, Ive got a difference in results depending on wether I run my app in the debugger, or run it seperatly (or with <ctrl-f5>) the results in the debugger seem to be more correct, although the app isnt finished and theres still a lot of things it gets wrong. the processing is so complex its hard to determine where the difference can be occuring, its a visual display of 3d models, and theres a couple of surfaces
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10264
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6716
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.