473,797 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String missing ending quote

>From my understanding, when a string is stored in VB.NET and you look
at it in the debugger, it has a quote on both sides to signify that it
is a string as opposed to a char or int or whatever. I've got a
simple program here (I actually found it on the web somewhere, but I'm
looking through it) that doesn't seem to have that ending quote at
when it gets down to the end.

In this program it doesn't make much of a difference, but I've
modified it a little and used it in another one where it needs to
decompress the string after it decrypts it and not having that ending
quote makes it crash.

Can anyone tell me what's going on here that makes that quote go away.

Also, I can't add anything to the end of the string when it comes out
of the last decryptTextFrom Memory. These two problems are probably
related.

Thanks ahead of time

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

Imports System.Security .Cryptography
Imports System.Text
Imports System.IO

Module TripleDESCSPSam ple

Sub Main()
Try
' Create a new TripleDESCrypto ServiceProvider object
' to generate a key and initialization vector (IV).
Dim tDESalg As New TripleDESCrypto ServiceProvider

' Create a string to encrypt.
Dim sData As String = "Here is some data to encrypt."

' Encrypt the string to an in-memory buffer.
Dim Data As Byte() = EncryptTextToMe mory(sData,
tDESalg.Key, tDESalg.IV)

' Decrypt the buffer back to a string.
Dim Final As String = DecryptTextFrom Memory(Data,
tDESalg.Key, tDESalg.IV)

' Display the decrypted string to the console.
Console.WriteLi ne(Final)
Catch e As Exception
Console.WriteLi ne(e.Message)
End Try
End Sub
Function EncryptTextToMe mory(ByVal Data As String, ByVal Key() As
Byte, ByVal IV() As Byte) As Byte()
Try
' Create a MemoryStream.
Dim mStream As New MemoryStream

' Create a CryptoStream using the MemoryStream
' and the passed key and initialization vector (IV).
Dim cStream As New CryptoStream(mS tream, _
New
TripleDESCrypto ServiceProvider ().CreateEncryp tor(Key, IV), _
CryptoStreamMod e.Write)

' Convert the passed string to a byte array.
Dim toEncrypt As Byte() = New
ASCIIEncoding() .GetBytes(Data)

' Write the byte array to the crypto stream and flush it.
cStream.Write(t oEncrypt, 0, toEncrypt.Lengt h)
cStream.FlushFi nalBlock()

' Get an array of bytes from the
' MemoryStream that holds the
' encrypted data.
Dim ret As Byte() = mStream.ToArray ()

' Close the streams.
cStream.Close()
mStream.Close()

' Return the encrypted buffer.
Return ret
Catch e As CryptographicEx ception
Console.WriteLi ne("A Cryptographic error occurred: {0}",
e.Message)
Return Nothing
End Try
End Function
Function DecryptTextFrom Memory(ByVal Data() As Byte, ByVal Key()
As Byte, ByVal IV() As Byte) As String
Try
' Create a new MemoryStream using the passed
' array of encrypted data.
Dim msDecrypt As New MemoryStream(Da ta)

' Create a CryptoStream using the MemoryStream
' and the passed key and initialization vector (IV).
Dim csDecrypt As New CryptoStream(ms Decrypt, _
New
TripleDESCrypto ServiceProvider ().CreateDecryp tor(Key, IV), _
CryptoStreamMod e.Read)

' Create buffer to hold the decrypted data.
Dim fromEncrypt(Dat a.Length) As Byte

' Read the decrypted data out of the crypto stream
' and place it into the temporary buffer.
csDecrypt.Read( fromEncrypt, 0, fromEncrypt.Len gth)

'Convert the buffer into a string and return it.
Return New ASCIIEncoding() .GetString(from Encrypt)
Catch e As CryptographicEx ception
Console.WriteLi ne("A Cryptographic error occurred: {0}",
e.Message)
Return Nothing
End Try
End Function
End Module

Feb 5 '07 #1
4 2195
we******@gmail. com wrote:
>>From my understanding, when a string is stored in VB.NET and you look
at it in the debugger, it has a quote on both sides to signify that it
is a string as opposed to a char or int or whatever. I've got a
simple program here (I actually found it on the web somewhere, but I'm
looking through it) that doesn't seem to have that ending quote at
when it gets down to the end.

In this program it doesn't make much of a difference, but I've
modified it a little and used it in another one where it needs to
decompress the string after it decrypts it and not having that ending
quote makes it crash.

Can anyone tell me what's going on here that makes that quote go away.

Also, I can't add anything to the end of the string when it comes out
of the last decryptTextFrom Memory. These two problems are probably
related.

Thanks ahead of time
What you are saying doesn't really make sense. The quotes that are
displayed by the debugger is not part of the string in any way, it's
just how the debugger displays the string.

As the quotes are not part of the string in the first place, they can't
be missing from the string either.

--
Göran Andersson
_____
http://www.guffa.com
Feb 6 '07 #2
On Feb 5, 6:04 pm, Göran Andersson <g...@guffa.com wrote:
wesbl...@gmail. com wrote:
>From my understanding, when a string is stored in VB.NET and you look
at it in the debugger, it has a quote on both sides to signify that it
is a string as opposed to a char or int or whatever. I've got a
simple program here (I actually found it on the web somewhere, but I'm
looking through it) that doesn't seem to have that ending quote at
when it gets down to the end.
In this program it doesn't make much of a difference, but I've
modified it a little and used it in another one where it needs to
decompress the string after it decrypts it and not having that ending
quote makes it crash.
Can anyone tell me what's going on here that makes that quote go away.
Also, I can't add anything to the end of the string when it comes out
of the last decryptTextFrom Memory. These two problems are probably
related.
Thanks ahead of time

What you are saying doesn't really make sense. The quotes that are
displayed by the debugger is not part of the string in any way, it's
just how the debugger displays the string.

As the quotes are not part of the string in the first place, they can't
be missing from the string either.

--
Göran Andersson
_____http://www.guffa.com
Yeah, I realize it doesn't make sense. That's why I'm so confused.
Maybe someone with more of a knowledge of VB could tell me what's
going on there, but even so, if I add another quote to the end of the
string in the debugger, it works fine.

I think the second part of my problem is probably related and might
make more sense to to someone. After I make the final call to
decryptTextFrom Memory, I can't concatenate any more text to the end of
the string. I can add to the beginning though.

Wesley

Feb 6 '07 #3
Wesley wrote:
>
Yeah, I realize it doesn't make sense. That's why I'm so confused.
Maybe someone with more of a knowledge of VB could tell me what's
going on there, but even so, if I add another quote to the end of the
string in the debugger, it works fine.
If it makes any difference, it's most likely not that you add a quote,
it's that you edit the string in the debugger. There is nothing special
about the quote character if you put it inside a string, you will
probably get the same effect if you add any other character.
I think the second part of my problem is probably related and might
make more sense to to someone. After I make the final call to
decryptTextFrom Memory, I can't concatenate any more text to the end of
the string. I can add to the beginning though.
What do you mean when you say that "you can't"? What did you try
exactly, and what happens when you try? Do you get an error message?

Strictly speaking, it's not possible to add anything to a string,
neither at the end nor at the beginning. If you concatenate strings, you
are copying the contents of the strings into a new instance of a string.

--
Göran Andersson
_____
http://www.guffa.com
Feb 6 '07 #4
On Feb 6, 1:28 pm, Göran Andersson <g...@guffa.com wrote:
Wesley wrote:
Yeah, I realize it doesn't make sense. That's why I'm so confused.
Maybe someone with more of a knowledge of VB could tell me what's
going on there, but even so, if I add another quote to the end of the
string in the debugger, it works fine.

If it makes any difference, it's most likely not that you add a quote,
it's that you edit the string in the debugger. There is nothing special
about the quote character if you put it inside a string, you will
probably get the same effect if you add any other character.
I think the second part of my problem is probably related and might
make more sense to to someone. After I make the final call to
decryptTextFrom Memory, I can't concatenate any more text to the end of
the string. I can add to the beginning though.

What do you mean when you say that "you can't"? What did you try
exactly, and what happens when you try? Do you get an error message?

Strictly speaking, it's not possible to add anything to a string,
neither at the end nor at the beginning. If you concatenate strings, you
are copying the contents of the strings into a new instance of a string.

--
Göran Andersson
_____http://www.guffa.com

I solved the problem. The issue was that the byte array that was
being converted to a string has some nulls at the end that were not
being taken out. Once I did that, the issue went away.

Feb 6 '07 #5

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

Similar topics

2
3105
by: Bengt Richter | last post by:
Why wouldn't quote-stuffing solve the problem, and let you treat \ as an ordinary character? In a raw string, it's no good for preventing end-of-quoting anyway, unless you want the literal \ in front of the quote you are escaping. Quote-stuffing is a variation on the old quote-doubling, extended to deal with triple quotes as well (which makes it a little like HDLC bit stuffing). IOW, treat \ as an ordinary character, and then if you...
9
8005
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., etc. The intent is to finish by assigning the list to a string that I would write to disk: recstr = string.join(recd,'')
29
4325
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return substring before a pattern), AFTER (return substring after a pattern), and BETWEEN (return substring between 2 patterns). My questions are: 1. Can any tell me how I can implement such functionality in C#? 2. Is it possible to add/include function...
34
2751
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is constant: i.e. five or the string is abc????? xyz How can i generalize it for any length of the string?
8
4510
by: Lothar Behrens | last post by:
Hi, I have selected strtok to be used in my string replacement function. But I lost the last token, if there is one. This string would be replaced select "name", "vorname", "userid", "passwort" from "users" order by "users"
5
1841
by: Curious | last post by:
I have: if (temp.Contains("Account") == true) { temp.Replace("Account", "Client"); } The "Account" is not replaced by "Client" after this operation. I used
23
2840
by: KIRAN | last post by:
Hi all, can i split a C string like this? char * p = "Hello \ World\n\r"; is this according to standard? Any help or link to standard regarding the above doubt is aprreciated... Regards, Kiran
3
6103
by: eBob.com | last post by:
Is there a regex pattern which will match a VB.Net string? I.E. a regex which matches ... "this is a ""vb.net"" string" (I don't want three matches in this case, I want one.) I've come up with various solutions for the two-double-quotes-in-a-row problem but none of them have worked out. Thanks, Bob
5
1948
by: EricW | last post by:
Hi, I have the following line in my code: strConnect = String.Format("Data Source={0},{1};Network Library=DBMSSOCN;Initial Catalog={2};Integrated Security=False;Trusted Connection=Yes;UID={3};PSW={4};", myServer, myDBPort, Database.Name, myDBUsername, myDBPassword)
0
9685
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
9537
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10469
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...
1
10209
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6803
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
5459
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2934
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.