473,785 Members | 2,165 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 13410
"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
2753
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
5380
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
1323
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
2533
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
1132
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
2500
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
3225
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
5897
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
8253
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
4851
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
9647
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
9489
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
10162
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
10100
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
9959
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
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.