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

Need Help Manipulating Strings (Remove/Replace)

Hi.

How Do I "UPDATE" a previously created string?
I have a problem where an XML string created in
an event handler fails because the string doesn't "UPDATE"
each time the event hanlder fires, but "APPENDS",
creating lots of repetition in the XML:

Quote:
XML Parsing Error: junk after document element

Location: http://localhost:5223/Presentation/set/progress.aspx
Line Number 1, Column 191:<?xml version='1.0' encoding='ISO-8859-1'?
><uploads><upload><filename>SomeVideo.gvi</filename><bytessent>0</
bytessent><filesize>12444894</filesize><percent>0</percent></upload></
uploads><?xml version='1.0' encoding='ISO-8859-1'?...

and, the built string inside the event handler method
looks like this:

Code:

Dim sbhtml As New System.Text.StringBuilder
sbhtml.Append("<Some XML Tag>")
etc...
Context.Response.ContentType = "text/xml"
Response.Write(sbhtml.ToString)

So, how do I update the string each time the event handler
fires, not append more xml to the recently created string?

Thanks.
Peter

Mar 16 '07 #1
7 1226
pbd22 <du*****@gmail.comwrote:
How Do I "UPDATE" a previously created string?
You can't. Strings are immutable.

All you can do is create a new string which has the appropriate
changes.
I have a problem where an XML string created in
an event handler fails because the string doesn't "UPDATE"
each time the event hanlder fires, but "APPENDS",
creating lots of repetition in the XML:
<snip>
Code:

Dim sbhtml As New System.Text.StringBuilder
sbhtml.Append("<Some XML Tag>")
etc...
Context.Response.ContentType = "text/xml"
Response.Write(sbhtml.ToString)
Well yes, if you write to the response stream each time, it *will*
effectively append it.

You need to decide what you want to write and *then* write it. You
can't "unwrite" bits of the response.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 16 '07 #2
On Mar 16, 12:28 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
pbd22 <dush...@gmail.comwrote:
How Do I "UPDATE" a previously created string?

You can't. Strings are immutable.

All you can do is create a new string which has the appropriate
changes.
I have a problem where an XML string created in
an event handler fails because the string doesn't "UPDATE"
each time the event hanlder fires, but "APPENDS",
creating lots of repetition in the XML:

<snip>
Code:
Dim sbhtml As New System.Text.StringBuilder
sbhtml.Append("<Some XML Tag>")
etc...
Context.Response.ContentType = "text/xml"
Response.Write(sbhtml.ToString)

Well yes, if you write to the response stream each time, it *will*
effectively append it.

You need to decide what you want to write and *then* write it. You
can't "unwrite" bits of the response.

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Thanks Jon,

It isn't a question of not knowing what I want to send. The probelm is
that the program has to send a lot as the upload data from the server
updates.

So, what would you suggest? I am returning the results of a progress
meter to the client. Depending on filesize, the response stream will
get at least 100 writes (ie - 1%, 2%, 3%, 3%, 3%, 4%, 5%, etc...). If
the client is going to throw an XML parser error every time lots of
XML
strings try to make their way from the server, then this method isn't
going
to work.

What will allow me to send well-formed XML from the server in the
manner
discussed above?

Thanks a alot.

Mar 16 '07 #3
pbd22 <du*****@gmail.comwrote:
It isn't a question of not knowing what I want to send. The probelm is
that the program has to send a lot as the upload data from the server
updates.

So, what would you suggest? I am returning the results of a progress
meter to the client. Depending on filesize, the response stream will
get at least 100 writes (ie - 1%, 2%, 3%, 3%, 3%, 4%, 5%, etc...). If
the client is going to throw an XML parser error every time lots of
XML strings try to make their way from the server, then this method isn't
going to work.

What will allow me to send well-formed XML from the server in the
manner discussed above?
You can't do progress messages that way with HTTP. It's not that kind
of protocol.

I would suggest that you send the client back a page which polls back
to the server show the current progress.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 16 '07 #4
On Mar 16, 1:47 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
pbd22 <dush...@gmail.comwrote:
It isn't a question of not knowing what I want to send. The probelm is
that the program has to send a lot as the upload data from the server
updates.
So, what would you suggest? I am returning the results of a progress
meter to the client. Depending on filesize, the response stream will
get at least 100 writes (ie - 1%, 2%, 3%, 3%, 3%, 4%, 5%, etc...). If
the client is going to throw an XML parser error every time lots of
XML strings try to make their way from the server, then this method isn't
going to work.
What will allow me to send well-formed XML from the server in the
manner discussed above?

You can't do progress messages that way with HTTP. It's not that kind
of protocol.

I would suggest that you send the client back a page which polls back
to the server show the current progress.

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
I guess I am a little confused as to how the upload data should be
coming from the server. I understand client polling loops (that
actually is what I was trying to do) but I am unclear as to how the
response text or xml should be returned to the client. Do you have
more specific examples of this?

Thanks very much.

Mar 16 '07 #5
pbd22 <du*****@gmail.comwrote:
I guess I am a little confused as to how the upload data should be
coming from the server. I understand client polling loops (that
actually is what I was trying to do) but I am unclear as to how the
response text or xml should be returned to the client. Do you have
more specific examples of this?
Each time the client polls, just return the current progress (1%, 5% or
whatever).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 16 '07 #6
On Mar 16, 2:19 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
pbd22 <dush...@gmail.comwrote:
I guess I am a little confused as to how the upload data should be
coming from the server. I understand client polling loops (that
actually is what I was trying to do) but I am unclear as to how the
response text or xml should be returned to the client. Do you have
more specific examples of this?

Each time the client polls, just return the current progress (1%, 5% or
whatever).

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Right, thanks. That is what I "thought" I was doing with the XML
style stringbuilder. I guess this is kind of a newbie question but,
how do I return the updated data at the moment the client polling loop
requests it? The only way I can think of doing this is to save the
event handler's progress variables in some sort of global class
that gets accessed by a different aspx form during its Page_Load
method.
Then, the client-side polling loop calls the new aspx page and
response.write
inside its Page_Load method returns the current progress (whatever
that may be).

Is this what you were thinking when you said "Each time the client
polls, just return the current progress (1%, 5% or whatever)."

thanks again.

Mar 18 '07 #7
pbd22 <du*****@gmail.comwrote:
Right, thanks. That is what I "thought" I was doing with the XML
style stringbuilder. I guess this is kind of a newbie question but,
how do I return the updated data at the moment the client polling loop
requests it? The only way I can think of doing this is to save the
event handler's progress variables in some sort of global class
that gets accessed by a different aspx form during its Page_Load
method.
You'll need to have the actual "work" being done in a different thread,
and saving information to the client's session. Then when the client
polls, use the information in the session to give the current progress.

Basically what you were saying, but using the session instead of a
global variable.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 18 '07 #8

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

Similar topics

5
by: Gary McCullough | last post by:
What I want to do sounds simple, but it's defeating me. I want to substitute all occurences of a colon : character in a string with an @ character -- unless the : occurs within a single or...
10
by: Segfahlt | last post by:
I have a fairly simple C# program that just needs to open up a fixed width file, convert each record to tab delimited and append a field to the end of it. The input files are between 300M and...
2
by: Roshawn Dawson | last post by:
Hi, Web sites, like Google, have the ability to remove certain common words from the users search. For example, if I were to type "php and .net", Google would remove the word "and." So, that...
3
by: Serge Rielau | last post by:
Hi folks, One the more frequently asked questions is how to "sum" up strings by virtue of concatenating them in an aggregate function. Her eis a rather simpel solution that may be worth sharing...
7
by: Chris Brat | last post by:
Hi, Is there a better way to replace/remove characters (specifically ' and " characters in my case, but it could be anything) in strings in a list, than this example to replace 'a' with 'b': ...
43
by: Frodo Baggins | last post by:
Hi all, We are using strcpy to copy strings in our app. This gave us problems when the destination buffer is not large enough. As a workaround, we wanted to replace calls to strcpy with strncpy....
4
by: JJ | last post by:
Is there a way of checking that a line with escape sequences in it, has no strings in it (apart from the escape sequences)? i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it a...
3
by: =?Utf-8?B?UGF1bCBXdQ==?= | last post by:
I need to replace the ascII strings in VC++ source code with unicode compatiable strings. That is I want to replace "abc" with _T("abc") excluding the strings in #include line or already in...
7
by: ojsimon | last post by:
Hi I found this script on a forum and have been trying to make it work, but all it returns is a blank screen, i tried using the debug error reporting but got nothing from that either just a blank...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.