473,714 Members | 2,470 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string >> byte array >> string representation >> byte array >> string !!

Hi

I have a problem, I have a string which needs to be converted to a
byte array, then have the string representation of this array stored
in an AD attribute. This string attribute then has to be read and the
string representation of the byte array has to be converted back to
the original byte array and converted back to the original string -
confused yet?

in psuedo

1.str="Hello World"
2.convert str to byte()
3.convert byte() to str2 = 272010101080108 011103208701110 114010801000
4.store str2
5.read str2
6.convert str2 to byte()
7.convert byte() to str

I am getting stuck on step 6, converting the representation of the
byte array back to the original byte array

any help woould be grately appreciated.

cheers
David
Nov 20 '05 #1
4 13406
"David Bargna" <da***@vista.fr ee-online.co.uk> schrieb
I have a problem, I have a string which needs to be converted to a
byte array, then have the string representation of this array
stored in an AD attribute. This string attribute then has to be read
and the string representation of the byte array has to be converted
back to the original byte array and converted back to the original
string - confused yet?

in psuedo

1.str="Hello World"
2.convert str to byte()
3.convert byte() to str2 = 272010101080108 011103208701110 114010801000
How do you get
"27201010108010 801110320870111 0114010801000"
?

4.store str2
5.read str2
6.convert str2 to byte()
7.convert byte() to str

I am getting stuck on step 6, converting the representation of the
byte array back to the original byte array

--
Armin

Nov 20 '05 #2
Hello,

"David Bargna" <da***@vista.fr ee-online.co.uk> schrieb:

in psuedo

1.str="Hello World"
2.convert str to byte()
3.convert byte() to str2 = 272010101080108 011103208701110 114010801000
4.store str2
5.read str2
6.convert str2 to byte()
7.convert byte() to str

I am getting stuck on step 6, converting the representation of the
byte array back to the original byte array


Have a look at the 'GetString' method of the 'Encoding' class.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3
"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message news:<Or******* *******@TK2MSFT NGP12.phx.gbl>. ..
Hello,

"David Bargna" <da***@vista.fr ee-online.co.uk> schrieb:

in psuedo

1.str="Hello World"
2.convert str to byte()
3.convert byte() to str2 = 272010101080108 011103208701110 114010801000
4.store str2
5.read str2
6.convert str2 to byte()
7.convert byte() to str

I am getting stuck on step 6, converting the representation of the
byte array back to the original byte array


Have a look at the 'GetString' method of the 'Encoding' class.


thanks guys, I've solved the problem using

Private Function hashext14(ByVal ext14 As String) As String
If ext14 = "" Then Return Nothing : Exit Function
Dim UE As New UnicodeEncoding ()
Dim by As Byte() = UE.GetBytes(ext 14)
Return Convert.ToBase6 4String(by)
End Function

Private Function unhashext14(ByV al hash As String) As String
On Error GoTo Err
If hash = "" Or hash = Nothing Then Return Nothing : Exit Function
Dim b As Byte
Dim q = Convert.FromBas e64String(hash)
Dim ret As String
For Each b In q
If b <> 0 Then

ret = ret + Chr(b)
End If
Next
Return ret
Err:
Return Nothing : Exit Function

End Function
Nov 20 '05 #4
David,
In case you didn't know, the 'Exit Function' in each of your functions are
not doing anything, you can delete them!
If ext14 = "" Then Return Nothing : Exit Function
If hash = "" Or hash = Nothing Then Return Nothing : Exit Function
Return Nothing : Exit Function
The Return statement itself will exit the function, so the " : Exit
Function" is dead code!

Consider using OrElse here: If hash = "" Or hash = Nothing Then Return Nothing If hash Is Nothing OrElse hash = "" Then Return Nothing

To check for Nothing you need (should) use the Is operator, the OrElse will
short circuit and not do the second part of the comparison if not needed.

Which is important in statements such as:
If hash Is Nothing OrElse hash.Length = 0 Then Return Nothing

As if hash is nothing, the hash.Length function will get a
NullReferenceEx ception. The OrElse won't bother checking hash.Length when
hash is Nothing.

Hope this helps
Jay

"David Bargna" <da***@vista.fr ee-online.co.uk> wrote in message
news:89******** *************** ***@posting.goo gle.com... "Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in message

news:<Or******* *******@TK2MSFT NGP12.phx.gbl>. ..
Hello,

"David Bargna" <da***@vista.fr ee-online.co.uk> schrieb:

in psuedo

1.str="Hello World"
2.convert str to byte()
3.convert byte() to str2 = 272010101080108 011103208701110 114010801000
4.store str2
5.read str2
6.convert str2 to byte()
7.convert byte() to str

I am getting stuck on step 6, converting the representation of the
byte array back to the original byte array


Have a look at the 'GetString' method of the 'Encoding' class.


thanks guys, I've solved the problem using

Private Function hashext14(ByVal ext14 As String) As String
If ext14 = "" Then Return Nothing : Exit Function
Dim UE As New UnicodeEncoding ()
Dim by As Byte() = UE.GetBytes(ext 14)
Return Convert.ToBase6 4String(by)
End Function

Private Function unhashext14(ByV al hash As String) As String
On Error GoTo Err
If hash = "" Or hash = Nothing Then Return Nothing : Exit Function
Dim b As Byte
Dim q = Convert.FromBas e64String(hash)
Dim ret As String
For Each b In q
If b <> 0 Then

ret = ret + Chr(b)
End If
Next
Return ret
Err:
Return Nothing : Exit Function

End Function

Nov 20 '05 #5

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

Similar topics

0
2748
by: Hessam | last post by:
Hello, I am designing a .net custom control in VS.net 7.1 and my control exposes an array of strings which are supposed to be the items to show. To do this have declared a private string variable and a public property which returns it. string options = new string; public string Options {
0
5375
by: Hessam | last post by:
Hello, I am designing a .net custom control in VS.net 7.1 and my control exposes an array of strings which are supposed to be the items to show. To do this have declared a private string variable and a public property which returns it. string options = new string; public string Options {
1
1321
by: Darrel | last post by:
What's wrong with this vb.net dim?: Dim imagesToSave As ArrayList = myString.split(",") With myString = comma delimited string. I keep getting an invalid cast error with that. It's late and I'm tired, so I'm likely missing the obvious.
1
2521
by: Eugene Anthony | last post by:
Private Function BStr2UStr(BStr) 'Byte string to Unicode string conversion Dim lngLoop BStr2UStr = "" For lngLoop = 1 to LenB(BStr) BStr2UStr = BStr2UStr & Chr(AscB(MidB(BStr,lngLoop,1))) Next End Function Private Function UStr2Bstr(UStr)
0
1131
by: Rajesh soni | last post by:
hi friends i got an error while building a web control.... this error is as follows. "Cannot create an object of type 'System.String' from its string representation 'String Array' for the 'Menus' property." in design time it is working good but in runtime of ASP.NET it shows this error...
10
2490
by: Shafik | last post by:
Hello, I am new to C++. I know the reason is probably template instantiation problems ... but what's the *real* reason I cannot declare a: vector<stringv = vector<string>(4); Thanks! --Shafik
2
3223
by: adh | last post by:
In c# you can return a String() but in VB.NET2005 it does not work (the webservice test sends to the error page). See MS AJAX Controls Toolkit.Autocomplete which demands a String() reply. I prefer doing it in VB but how? Thanks, adh *** Sent via Developersdex http://www.developersdex.com ***
2
5892
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the dictionary essentially creates the following array: Key Value
4
8247
by: J Peyret | last post by:
Well, as usual I am confused by unicode encoding errors. I have a string with problematic characters in it which I'd like to put into a postgresql table. That results in a postgresql error so I am trying to fix things with <string>.encode he Company�s ticker Trying for an encode:
5
4849
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. Dim Array() As Char Dim strwork As String = "76A3kj9d6" Array = strwork.ToCharArray OR
0
8802
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
8711
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
9314
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
9175
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...
1
9075
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
9017
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
5948
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();...
2
2522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2111
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.