|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Two byte in one string?Hello,
how can I put two byte in one String , and I want that this one byte be behind second? Like this : Dim b1,b2 As Byte ("b1=2D") ("b2=52") Dim s As String = b1&b2 ("2D52") Did this code put first byte behaind second in "str" (string)? >how can I put two byte in one String , and I want that this one byte be Are you looking for>behind second? Dim s As String = b1.ToString("X2") & b2.ToString("X2") Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Yes,
but I have one more question. Can I put second byte in different time in string? Because, I have situation like this, I read two byte from serial port, with distance, and because I nead put first byte diferend on second in string. Mattias: What is "X" in Yours code? What this mean? Thank you ! Bojan Show quote "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:O%23na2PvzGHA.3464@TK2MSFTNGP03.phx.gbl... > >>how can I put two byte in one String , and I want that this one byte be >>behind second? > > Are you looking for > > Dim s As String = b1.ToString("X2") & b2.ToString("X2") > > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. Hi Bojan,
You can assemble the string any way you want. The X2 means output as 2-digit hexadecimal value. On Sun, 03 Sep 2006 09:18:22 +0200, Bojan <bojan.b***@pu.t-com.hr> wrote: Show quote > Yes, > but I have one more question. Can I put second byte in different time in > string? Because, I have situation like this, I read two byte from serial > port, with distance, and because I nead put first byte diferend on second in > string. > > Mattias: > What is "X" in Yours code? What this mean? > > Thank you ! > Bojan > > > > "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message > news:O%23na2PvzGHA.3464@TK2MSFTNGP03.phx.gbl... >> >>> how can I put two byte in one String , and I want that this one byte be >>> behind second? >> >> Are you looking for >> >> Dim s As String = b1.ToString("X2") & b2.ToString("X2") >> >> >> Mattias >> >> -- >> Mattias Sjögren [C# MVP] mattias @ mvps.org >> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >> Please reply only to the newsgroup. > > > -- Happy coding! Morten Wennevik [C# MVP] >Can I put second byte in different time in string? Sure, just use the & operator to append the new string.Dim s As String = b1.ToString("X2") .... s = s & b2.ToString("X2") If you actually have many more bytes, you should consider using the System.Text.StringBuilder class instead. >What is "X" in Yours code? What this mean? It means that the number should be formatted with upper-casehexadecimal digits. See http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Other interesting topics
|
|||||||||||||||||||||||