473,748 Members | 3,585 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Byte to Char

Hello,

Suppose I have the following C# code which I want to convert to VB:

for (int i = 0; i < nFieldLength; i++)
Console.Write(( char) sValue[i]);

sValue is a byte [] array.

The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work. Instead
the compiler said it can't convert Byte to Char.

Thanks in advance.

-- John
Nov 21 '05 #1
4 42919
Hi,

Take a look at chr(svalue(i))
http://msdn.microsoft.com/library/de...l/vafctChr.asp

Ken
------------------
"John Smith" <jo********@x-formation.com> wrote in message
news:Oy******** ******@TK2MSFTN GP15.phx.gbl...
Hello,

Suppose I have the following C# code which I want to convert to VB:

for (int i = 0; i < nFieldLength; i++)
Console.Write(( char) sValue[i]);

sValue is a byte [] array.

The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work. Instead
the compiler said it can't convert Byte to Char.

Thanks in advance.

-- John

Nov 21 '05 #2
John,

Dim a as char = chrw(65)
dim b as byte = ascw("A")

For me are the convert functions one of the things which I like very much
from VBNet.

http://msdn.microsoft.com/library/de...conversion.asp

http://support.microsoft.com/default...b;en-us;145745

I hope this helps?

Cor

"John Smith" <jo********@x-formation.com>
....
Hello,

Suppose I have the following C# code which I want to convert to VB:

for (int i = 0; i < nFieldLength; i++)
Console.Write(( char) sValue[i]);

sValue is a byte [] array.

The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work.
Instead
the compiler said it can't convert Byte to Char.

Thanks in advance.

-- John

Nov 21 '05 #3
"John Smith" <jo********@x-formation.com> schrieb:
The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work.
Instead
the compiler said it can't convert Byte to Char.


'CChar', 'Chr', 'ChrW', 'Convert.ToChar ', ...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

"John Smith" <jo********@x-formation.com> wrote in message
news:Oy******** ******@TK2MSFTN GP15.phx.gbl...
Hello,

Suppose I have the following C# code which I want to convert to VB:

for (int i = 0; i < nFieldLength; i++)
Console.Write(( char) sValue[i]);

sValue is a byte [] array.

The problem is the typecast which I can't find an equivalent for in VB. I
tried using CChar() and CType() but neither of them seemed to work.
Instead
the compiler said it can't convert Byte to Char.

Thanks in advance.

-- John


Dim s As String = "Hello World!"
Dim bytes As Byte() = System.Text.ASC IIEncoding.ASCI I.GetBytes(s)
Dim output As String = System.Text.ASC IIEncoding.ASCI I.GetString(byt es)
Console.WriteLi ne(output)

Mythran
Nov 21 '05 #5

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

Similar topics

13
7922
by: Bryan Parkoff | last post by:
I have two variables: "char A" and "short B". I can be able to convert from A to B using explicit case conversion with no problem like "B = short (A);". Right now, I have two variables: "char T" and "short A". T has an array of six elements. I desire to capture first element and second element as two bytes into word as short. The problem is that "A" captures only one element instead of two elements. I have looked at machine language...
15
34601
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
25
7298
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As Byte Dim b As Byte
3
2259
by: Eric BOUXIROT | last post by:
hi, i must convert all of these eVC++ prototypes to use with VB.NET.... DLLEXPORT long F_BDO_MessageBoxOK(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_MessageBoxOUINON(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_CalculAXplusB(short int *IN_Tab_entree ,int IN_taille , double *OUT_Tab_sortie_freq , double *OUT_Tab_sortie, double IN_A,
65
21453
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. #include <string.h> #include <stdio.h> /* Convert an ipv4 address to long integer */ /* "192.168.1.1" --> 3232235777 */ unsigned long iptol(char *ip){
3
3652
by: David | last post by:
Hi, how to convert a char array(byte) to a string variable? byte buffer; string strTest; /*the blow codes all get type of 'buffer': System.Byte! strTest = buffer.ToString() strTest = System.Convert.ToString(buffer)
5
3907
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile) ) { int fileSize = (int)fs.Length; int buffer = fileSize; byte b = new byte;
4
4660
by: Peter | last post by:
Does anyone know how to convert the following VB6 code to C# code? Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long) Dim sngArray(0) As Single strString = Chr$(107) & Chr$(62) & Chr(139) & Chr$(65) CopyMemory sngArray(0), ByVal strString, Len(strString) After running the code sngArray(0) = 17.40548
12
13549
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} System.Text.UTF8Encoding str = new System.Text.UTF8Encoding(); string s = new string((char)107, 1); s += new string((char)62, 1);
0
8984
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
8823
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
9363
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
9312
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,...
1
6793
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...
0
4593
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
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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.