473,396 Members | 2,030 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,396 software developers and data experts.

string s=""+(char)34; != Chr(34) and also != \" etc.


None of the following properly do the VB.net double quote conversion because
all of the following in csharp convert to

\" instead of just a double quote: "

I have tried:

char myDoubleQuote = (char)34;

string myDoubleQuote = "" + (char)34;

string myDoubleQuote = "\"";

myItems = "<?xml version=" + myDoubleQuote + "1.0" + myDoubleQuote +
"?><users>" & myXml & "</users>"

I even tried:
myItems = "<?xml version=<![CDATA["]]>1.0<![CDATA["]]>?><users>" &
myXml & "</users>"
it does not compile.


I need the string myItems to be able to properly handle the creation of one
double quote on each side of 1.0 :

myItems = <?xml version="1.0"?><users+ myXml + "</users>

Thank you for your help with this problem!

Jun 27 '08 #1
13 7903
On Sun, 15 Jun 2008 17:08:34 -0700, xzzy <mr********@comcast.netwrote:
[...]
I need the string myItems to be able to properly handle the creation of
one
double quote on each side of 1.0 :

myItems = <?xml version="1.0"?><users+ myXml + "</users>
Assuming that the extra double-quote just before "</users>" is a typo,
this should work:

string myItems = "<?xml version=\"1.0\"?><users>" + myXml + "</users>"

No hoop-jumping required.

If that's not working for you, then you will need to post a
concise-but-complete code sample, so that we can see what else is
happening to your string.

Pete
Jun 27 '08 #2
only my opinion, Lisp and Double Quotes . . . they both should be taken to
the alley so that instead of dying by inches, they can die by the yard.

Peter, thank you for your time, in different words, I need the string
myItems to be able to properly handle the creation of one double quote on
each side of 1.0 :

The end result must be:
<?xml version="1.0"?blahblahblah</users>

given that 'myItems' is a string being built, how to generate: <?xml
version="1.0"? in csharp to pass to xml

Sorry I did not explain as well as I could, maybe in different words there
is a better understanding of the problem.
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 15 Jun 2008 17:08:34 -0700, xzzy <mr********@comcast.netwrote:
[...]
I need the string myItems to be able to properly handle the creation of
one
double quote on each side of 1.0 :

myItems = <?xml version="1.0"?><users+ myXml + "</users>
Assuming that the extra double-quote just before "</users>" is a typo,
this should work:

string myItems = "<?xml version=\"1.0\"?><users>" + myXml + "</users>"

No hoop-jumping required.

If that's not working for you, then you will need to post a
concise-but-complete code sample, so that we can see what else is
happening to your string.

Pete
Jun 27 '08 #3
On Sun, 15 Jun 2008 18:09:11 -0700, xzzy <mr********@comcast.netwrote:
[...]
Peter, thank you for your time, in different words, I need the string
myItems to be able to properly handle the creation of one double quote on
each side of 1.0 :
The code I posted does that.
Jun 27 '08 #4
string myItems = "<?xml version=\"1.0\"?><users>" + myXml + "</users>"

Produces:
<?xml version=\"1.0\"? etc . . .
the csharp
string myItems = "<?xml version=\"1.0\"?>

result must be:

string myItems = "<?xml version="1.0"?>
Jun 27 '08 #5
On Sun, 15 Jun 2008 18:37:45 -0700, xzzy <mr********@comcast.netwrote:
string myItems = "<?xml version=\"1.0\"?><users>" + myXml + "</users>"

Produces:
<?xml version=\"1.0\"? etc . . .
No, it doesn't. It only looks that way because you are looking at it in
the debugger, and the debugger will quote quotes found in a string when
displaying the string on the screen.

If you write the string to file, you will see it's exactly as you want.

Pete
Jun 27 '08 #6
If I run the VB.net version = okay, it works

any variation of the csharp version = the error message 'Too many automatic
redirection attemps"

the problem is the difference between \" in csharp ( or above csharp
attempts to render a " ( they all end up being \" ), and vb.net "" properly
rendering "" to "

I"m thinking taking a diskette to the alley is appropriate . . .
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 15 Jun 2008 18:37:45 -0700, xzzy <mr********@comcast.netwrote:
string myItems = "<?xml version=\"1.0\"?><users>" + myXml + "</users>"

Produces:
<?xml version=\"1.0\"? etc . . .
No, it doesn't. It only looks that way because you are looking at it in
the debugger, and the debugger will quote quotes found in a string when
displaying the string on the screen.

If you write the string to file, you will see it's exactly as you want.

Pete
Jun 27 '08 #7
I am version 1.1 and all service packs, I cannot use 2.0 or more recent due
to a very bad Microsoft decision about sessions beginning v2 ( meaning not
regarding session variables )
Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 15 Jun 2008 18:37:45 -0700, xzzy <mr********@comcast.netwrote:
string myItems = "<?xml version=\"1.0\"?><users>" + myXml + "</users>"

Produces:
<?xml version=\"1.0\"? etc . . .
No, it doesn't. It only looks that way because you are looking at it in
the debugger, and the debugger will quote quotes found in a string when
displaying the string on the screen.

If you write the string to file, you will see it's exactly as you want.

Pete
Jun 27 '08 #8
On Sun, 15 Jun 2008 19:18:02 -0700, xzzy <mr********@comcast.netwrote:
If I run the VB.net version = okay, it works

any variation of the csharp version = the error message 'Too many
automatic
redirection attemps"
Error message from what? The code I posted would not emit that error
message. As I mentioned from the outset, if you don't post code, it's
practically impossible to answer your question.
[...]
I"m thinking taking a diskette to the alley is appropriate . . .
Sure. For some people, that's a better solution than learning how to use
the language. YMMV.

Pete
Jun 27 '08 #9
xzzy formulated on maandag :
If I run the VB.net version = okay, it works

any variation of the csharp version = the error message 'Too many automatic
redirection attemps"

the problem is the difference between \" in csharp ( or above csharp
attempts to render a " ( they all end up being \" ), and vb.net "" properly
rendering "" to "
As Peter said, that is just the debugger trying to be helpful and
displaying the string in a way that would be legal in sourcecode.
s = "<xml version="1.0">"; is not legal C#
s = "<xml version=\"1.0\">"; *is*

You could also see s = @"embedded\backslash", where the @ is just 'C#'
for "string literal", not a part of the contents of the string.

See also http://www.yoda.arachsys.com/csharp/....html#debugger

Try writing that string to a file (you won't see that '\') or try
getting the length of that string (the '\' is not counted as it is not
there).

Hans Kesting
Jun 27 '08 #10
Thank you for your time and help.

The website is in csharp and I solved the quote problem by having the
offending page ( it creates an xml file of state/provience names when the
viewer selects a different country ) be in vb.net as:

<%@ Page Language="vb" %>
<script language="VB" runat="server">

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
.......

and let vb.net do it's thing with quotes.
"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:uI**************@TK2MSFTNGP06.phx.gbl...
xzzy formulated on maandag :
>If I run the VB.net version = okay, it works

any variation of the csharp version = the error message 'Too many
automatic redirection attemps"

the problem is the difference between \" in csharp ( or above csharp
attempts to render a " ( they all end up being \" ), and vb.net ""
properly rendering "" to "

As Peter said, that is just the debugger trying to be helpful and
displaying the string in a way that would be legal in sourcecode.
s = "<xml version="1.0">"; is not legal C#
s = "<xml version=\"1.0\">"; *is*

You could also see s = @"embedded\backslash", where the @ is just 'C#' for
"string literal", not a part of the contents of the string.

See also http://www.yoda.arachsys.com/csharp/....html#debugger

Try writing that string to a file (you won't see that '\') or try getting
the length of that string (the '\' is not counted as it is not there).

Hans Kesting


Jun 27 '08 #11
Peter has already shown you how to do it, but here is an example:

Suppose your end game is this:

<?xml version="1.0"?>
<users>
<user>
<id>1</id>
<name>Greg</name>
</user>
</users>

And you are building the individual users in a loop. So, let's create a
testable method that returns a single user, knowing we are going to loop
later:

public static string CreateUsersAsXml()
{
//pretend we are pulling from database
int id = 1;
string name = "Greg";

StringBuilder builder = new StringBuilder();
//tabs and returns for readability
builder.Append("<user>");

builder.Append("<id>");
builder.Append(id);
builder.Append("</id>");

builder.Append("<name>");
builder.Append(name);
builder.Append("</name>");

builder.Append("</user>");

return builder.ToString();
}

You can now test to make sure it returns:
<user><id>1</id><name>Greg</name></user>

[TestMethod]
public void DoesXmlCreatorReturnCorrectXmlStringTest()
{
string expected = "<user><id>1</id><name>Greg</name></user>";
string actual = MyXmlCreator.CreateUsersAsXml();

Assert.AreEqual(expected, actual, "Xml String are not equal");
}

Now, to your problem, the \" (which is not a problem). Put this in a console
application and do the following:

public static string GetXmlUsers()
{
string myXml = MyXmlCreator.CreateUsersAsXml();

//Should use a StringBuilder here
string xml = "<?xml version=\"1.0\"?><users>" + myXml + "</users>";

StringReader reader = new StringReader(xml);

XmlDocument doc = new XmlDocument();
doc.Load(reader);

return doc.InnerXml.ToString();
}

Output, as expected is:
<?xml version="1.0"?><users><user><id>1</id><name>Greg</name></user></users>

Here is the entire program in a Console Application so you can test it:

class Program
{
static void Main(string[] args)
{
string myXml = CreateUsersAsXml();
string xml = "<?xml version=\"1.0\"?><users>" + myXml + "</users>";

StringReader reader = new StringReader(xml);

XmlDocument doc = new XmlDocument();
doc.Load(reader);

XmlNode node = doc.SelectSingleNode("users/user/id");
Console.WriteLine(node.FirstChild.Value);
Console.Write(doc.InnerXml.ToString());

Console.Read();
}
public static string CreateUsersAsXml()
{
//pretend we are pulling from database
int id = 1;
string name = "Greg";

StringBuilder builder = new StringBuilder();
//tabs and returns for readability
builder.Append("<user>");

builder.Append("<id>");
builder.Append(id);
builder.Append("</id>");

builder.Append("<name>");
builder.Append(name);
builder.Append("</name>");

builder.Append("</user>");

return builder.ToString();
}
}

Note that the \" is equivalent to "" when used in this manner. Also note
that this works, as the XML is properly loaded into an XML document and you
can even consume as XML. This is proven in the statement:

XmlNode node = doc.SelectSingleNode("users/user/id");
Console.WriteLine(node.FirstChild.Value);

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
"xzzy" <mr********@comcast.netwrote in message
news:y4******************************@comcast.com. ..
>
None of the following properly do the VB.net double quote conversion
because all of the following in csharp convert to

\" instead of just a double quote: "

I have tried:

char myDoubleQuote = (char)34;

string myDoubleQuote = "" + (char)34;

string myDoubleQuote = "\"";

myItems = "<?xml version=" + myDoubleQuote + "1.0" + myDoubleQuote
+ "?><users>" & myXml & "</users>"

I even tried:
myItems = "<?xml version=<![CDATA["]]>1.0<![CDATA["]]>?><users>" &
myXml & "</users>"
it does not compile.


I need the string myItems to be able to properly handle the creation of
one double quote on each side of 1.0 :

myItems = <?xml version="1.0"?><users+ myXml + "</users>

Thank you for your help with this problem!
Jun 27 '08 #12
What do you mean here about "a very bad Microsoft decision about sessions
beginning v2"? Can you explain this in more detail, as I am stumped.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

********************************************
| Think outside the box! |
********************************************
"xzzy" <mr********@comcast.netwrote in message
news:Xq******************************@comcast.com. ..
>I am version 1.1 and all service packs, I cannot use 2.0 or more recent
due to a very bad Microsoft decision about sessions beginning v2 ( meaning
not regarding session variables )
Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sun, 15 Jun 2008 18:37:45 -0700, xzzy <mr********@comcast.netwrote:
>string myItems = "<?xml version=\"1.0\"?><users>" + myXml + "</users>"

Produces:
<?xml version=\"1.0\"? etc . . .

No, it doesn't. It only looks that way because you are looking at it in
the debugger, and the debugger will quote quotes found in a string when
displaying the string on the screen.

If you write the string to file, you will see it's exactly as you want.

Pete
Jun 27 '08 #13
Hans Kesting wrote:
xzzy formulated on maandag :
>If I run the VB.net version = okay, it works

any variation of the csharp version = the error message 'Too many
automatic redirection attemps"

the problem is the difference between \" in csharp ( or above csharp
attempts to render a " ( they all end up being \" ), and vb.net ""
properly rendering "" to "

As Peter said, that is just the debugger trying to be helpful and
displaying the string in a way that would be legal in sourcecode.
s = "<xml version="1.0">"; is not legal C#
s = "<xml version=\"1.0\">"; *is*
And from a practical point of view I would suggest:

s = "<xml version='1.0'>";

same functionality and more readable !

Arme
Jun 27 '08 #14

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

Similar topics

7
by: Tino Lange | last post by:
Hi! I identified a bottleneck in my programs. I just want to "encrypt" data by easy xoring. Ok - that's no encryption at all - I know. But it's hardly readable - and that's enough :-) Just...
14
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
4
by: Robert | last post by:
Hello. I have tried to remove the char "\" from a string that I am building in codebehind. to be used in a script tag. I have tried adding (char)34 to the string instead of the escape...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
8
by: js | last post by:
HI guys, How do you write Perl's print a ... z, A ... Z, "\n"' in Python In Python?
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
0
by: Cor Ligthert[MVP] | last post by:
Probably you have a wrong time at your system, can you change that
16
by: hiteshthappa | last post by:
hi Can anyone please help me in finding the total number of words in a file I get the newlines, characters and blankspaces correctly but counting words ia problem.I have tried many ways but it...
7
by: Luna Moon | last post by:
#include "stdafx.h" #include <iostream> #include <string> using namespace std; int main() { string cc(31, 'c'); string bb=cc.assign(3, 'dd');
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?
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
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...
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...

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.