Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Wednesday, March 28, 2012

String.Length issue

Hi. I've got a vb.net/asp.net application that passes strings back a
forth between a c++ COM object. We use simple tagging to designate
what's what, and it's worked pretty well until now. We had some data
that wasn't parsing right because it also contained tags that conflicted
with the tags designating the data.
To get around this the programmer of the COM object (not me) decided we
could put string lengths in the tags, so if an element was called x, I'd
send <x L=3>123</x> with the L= indicating the length of the string. So
I wrote a tagging function to take care of this that uses the
String.Length property to calculate the length of the string. Then I
send the following string, and he can't parse it out:

<body L=579>Dear MATT B--

Thanks for purchasing Print@dotnet.itags.org.Home tickets!
Included in this this email is a link to your ticket(s) from sale id
**SUB(wwsale_id).
To retrieve your tickets, please click (or copy/paste into your browser)
the link below:
<http://localhost/webwaresales1/GetTix.aspx?req=kXU%2bANUsFnl4YlNHjua5lA%3d%3d
You will need Adobe Acrobat Reader (available free from
http://www.adobe.com)
to view or print your items.

You will need to bring your printed tickets with you to the resort.

Thanks again and we look forward to seeing you soon!

S---, Inc.</body
The other guy said he calculates a length of 551 but if I use
String.Length I get 579. Incidentally, if I paste the string into
TextPad and look at the document properties, it says 551 characters and
a file size of 579.
So can anyone explain where the difference (28) comes from? It's not the
number of lines (15) and I don't see any other special characters
besides line endings.

Thanks!

MattMattB <somedudeus@.yahoo.com> wrote in news:3n41c6F19h9o1U3@.individual.net:

> The other guy said he calculates a length of 551 but if I use
> String.Length I get 579. Incidentally, if I paste the string into
> TextPad and look at the document properties, it says 551 characters and
> a file size of 579.
> So can anyone explain where the difference (28) comes from? It's not the
> number of lines (15) and I don't see any other special characters
> besides line endings.

Line endings actually take up 2 bytes in Windows. Carriage Return and Line
Feed.

So 579 bytes is correct - there are 15 lines, but only 14 CR + LF. So:

551 bytes + (14 CRLF x 2 bytes) = 579 : )

BTW, didn't the other guy calculate 579 too? (<body L=579>).

--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

String.Length issue

Hi. I've got a vb.net/asp.net application that passes strings back a
forth between a c++ COM object. We use simple tagging to designate
what's what, and it's worked pretty well until now. We had some data
that wasn't parsing right because it also contained tags that conflicted
with the tags designating the data.
To get around this the programmer of the COM object (not me) decided we
could put string lengths in the tags, so if an element was called x, I'd
send <x L=3>123</x> with the L= indicating the length of the string. So
I wrote a tagging function to take care of this that uses the
String.Length property to calculate the length of the string. Then I
send the following string, and he can't parse it out:
<body L=579>Dear MATT B--
Thanks for purchasing Print@dotnet.itags.org.Home tickets!
Included in this this email is a link to your ticket(s) from sale id
**SUB(wwsale_id).
To retrieve your tickets, please click (or copy/paste into your browser)
the link below:
<http://localhost/webwaresales1/GetT...//www.adobe.com)
to view or print your items.
You will need to bring your printed tickets with you to the resort.
Thanks again and we look forward to seeing you soon!
S--, Inc.</body>
The other guy said he calculates a length of 551 but if I use
String.Length I get 579. Incidentally, if I paste the string into
TextPad and look at the document properties, it says 551 characters and
a file size of 579.
So can anyone explain where the difference (28) comes from? It's not the
number of lines (15) and I don't see any other special characters
besides line endings.
Thanks!
MattMattB <somedudeus@.yahoo.com> wrote in news:3n41c6F19h9o1U3@.individual.net:

> The other guy said he calculates a length of 551 but if I use
> String.Length I get 579. Incidentally, if I paste the string into
> TextPad and look at the document properties, it says 551 characters and
> a file size of 579.
> So can anyone explain where the difference (28) comes from? It's not the
> number of lines (15) and I don't see any other special characters
> besides line endings.
Line endings actually take up 2 bytes in Windows. Carriage Return and Line
Feed.
So 579 bytes is correct - there are 15 lines, but only 14 CR + LF. So:
551 bytes + (14 CRLF x 2 bytes) = 579 : )
BTW, didn't the other guy calculate 579 too? (<body L=579> ).
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]

Monday, March 26, 2012

String/Number manip.

In the following line:
txtWage.Text = "$" & Trim(dataReader.GetValue(9).ToString)

It returns $20.0000 I only want it to return back $20.00 -- every search I've done in string manip. has shown me zilch.

Any suggestions?

txtWage.Text = Format(CDbl(Trim(dataReader.GetValue(9).ToString)), "currency")
I think you can use String.Format also to do the same thing, with the format of {0:c}

Stringbuilder Class

Could anyone show me the code that allows me reset a Stringbuilder back to
either null or nothing or a blank space?How about this?
sb.Length = 0
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
> Could anyone show me the code that allows me reset a Stringbuilder back to
> either null or nothing or a blank space?
Yes, just tested but my comp. is incr. slow at home.
Dim sb As New StringBuilder
sb.Append("Hello")
MsgBox(sb.ToString)
sb.Length = 0
MsgBox(sb.ToString)
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> schreef in bericht
news:OUdAFyd9FHA.2640@.tk2msftngp13.phx.gbl...
> How about this?
> sb.Length = 0
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
>
Hi Paul,
It looks like you can set the Length to zero or just use New again.
Here's a little demo:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim sb As New StringBuilder
sb.Append("!", 50)
sb.Append(": Length is now " & sb.Length.ToString)
Label1.Text = sb.ToString
sb.Length = 0
Label2.Text = "After Length=0:" & sb.ToString
sb = New StringBuilder
End Sub
Ken
Microsoft MVP [ASP.NET]
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
> Could anyone show me the code that allows me reset a Stringbuilder back to
> either null or nothing or a blank space?
Actually, I tried using New again and that did not seem to work.
Setting the length to 0 did work.
Thank you for your assistance.
"Ken Cox" wrote:

> Hi Paul,
> It looks like you can set the Length to zero or just use New again.
> Here's a little demo:
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs)
> Dim sb As New StringBuilder
> sb.Append("!", 50)
> sb.Append(": Length is now " & sb.Length.ToString)
> Label1.Text = sb.ToString
> sb.Length = 0
> Label2.Text = "After Length=0:" & sb.ToString
> sb = New StringBuilder
> End Sub
> Ken
> Microsoft MVP [ASP.NET]
>
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:972F577C-0629-4B47-98EA-E403F429BB84@.microsoft.com...
>
>

Saturday, March 24, 2012

Strings, webformatting

Hey.

I believe when I was reading through unleashed, I saw a function that converts strings to a nice webform and back again, but I can't remember, and I can't find it again, LOL...

Basically,

What I want to do:

I email users a web address containing their email and validation code

example:

http://mySite.com/verify.aspx?User=<user name>&Code=<code
now this is working awesome, except, if the username had a space in it, the system falls down (as the link stops where the space is)

so basically, I wanna know if there is a function I can run on the string containing the web address that will convert the spaces to %20, and if there is a function that converts it back again (%20's to a space).

I'm sure I could code my own function and put it in a namespace or something, but it'd be so much nicer if there was a default function (YAY)

is there? or am I stark raving mad?!?! lol

Thanks for your help
-AshleighHi Ashleigh

Perhaps the "Server.URLEncode" and "Server.UrlDecode" will help you.

Tuesday, March 13, 2012

Stuck on v2 ConfigurationSection class

Back in "the day" of beta 1 of .NET v2, I could:
XmlNode myNode = ConfigurationSection.GetRawXml().SelectSingleNode("myNode");
Well, that GetRawXml() method has since gone away. How do I do the same thing? Brain hurts getting my head around the changes.The new model is meant to wrap the parsing and management of XML for you. In what context are you asking the question? Is this from the implementor of the ConfigurationSection or from a client wanting the read the configuration section information?
-Brock

Are you writing your own configuration section? Is that is a yes, you could try overriding DeserializeElement() method, like this:
public sealed class MySection : ConfigurationSection
{
[...]
private string _rawXml;

public string RawXml
{
get
{
return _rawXml;
}
}
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
{
base.DeserializeElement(reader, serializeCollectionKey);
_rawXml = reader.ReadOuterXml();
}
[...]
}
Brock, I don't actually care if I can't get the actual XML as long as Ican get to the data in it, if the revised object model will allow me todo that. There are quite a few changes from beta 1 to 2 in this areaand I haven't been paying close enough attention to figure them out.

Hello.
well, now everything is better. all the sections are strongly typed and you can get them by using the Configuration API. take a look here and see if this helps:
http://beta.asp.net/QUICKSTART/aspnet/doc/management/retrieve.aspx
Here's a sample I recently put together for someone else:
http://staff.develop.com/ballen/samples/configuration20.zip
-Brock