473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

This could be shorter tight? (String to Hex)

public static String StringToHex(String sString)
{
if (sString.Length == 0) { return ""; }
StringBuilder sb = new StringBuilder(sString.Length * 2);
Char[] chars = sString.ToCharArray();
String T = "";
foreach (Char c in chars)
{
T = "0" + Convert.ToString(c, 16).ToUpper();
sb.Append(T.Substring (T.Length -2 ));
}
return sb.ToString();
}
Feb 17 '06 #1
2 1997
Sorry, did not understand from your code what is this function suppose to
do.
Please tell us what you want to get out of the function with name
StringToHex

George.

"Edwin Knoppert" <ne**@hellobasic.com> wrote in message
news:43**********************@text.nova.planet.nl. ..
public static String StringToHex(String sString)
{
if (sString.Length == 0) { return ""; }
StringBuilder sb = new StringBuilder(sString.Length * 2);
Char[] chars = sString.ToCharArray();
String T = "";
foreach (Char c in chars)
{
T = "0" + Convert.ToString(c, 16).ToUpper();
sb.Append(T.Substring (T.Length -2 ));
}
return sb.ToString();
}

Feb 17 '06 #2
Don't let the unicode string fool you.
Just wanted to convert a string (with ansi chars) to two-byte hex notation.
Using a string for in and out is simply convienant.
The VB part has an Hex() function, c has value converters.
"George Ter-Saakov" <gt****@cardone.com> schreef in bericht
news:uO**************@TK2MSFTNGP11.phx.gbl...
Sorry, did not understand from your code what is this function suppose to
do.
Please tell us what you want to get out of the function with name
StringToHex

George.

"Edwin Knoppert" <ne**@hellobasic.com> wrote in message
news:43**********************@text.nova.planet.nl. ..
public static String StringToHex(String sString)
{
if (sString.Length == 0) { return ""; }
StringBuilder sb = new StringBuilder(sString.Length * 2);
Char[] chars = sString.ToCharArray();
String T = "";
foreach (Char c in chars)
{
T = "0" + Convert.ToString(c, 16).ToUpper();
sb.Append(T.Substring (T.Length -2 ));
}
return sb.ToString();
}


Feb 17 '06 #3

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

Similar topics

2
by: Zulik | last post by:
Hello, I have a problem with MessageDigest MD5 in Java. I want to calculate the digest from a file, encode it in base64 and display it. Now, according to MD5 spec, digest shall be 128 bits so,...
5
by: Alexander Eisenhuth | last post by:
Hallo all there, maby I don't see the forest because of all that trees, but : from struct import * # how can I convert f = float(0.5)
3
by: Ron Adam | last post by:
How do I covert a string hex or oct value to the correct int value? >>> s = oct(500) >>> s # returns a oct string '0764' >>> int(0764) # ok 500 >>> int(s) # this gives the...
1
by: PHP2 | last post by:
I have one large number with 18 decimal places for license key. have any way that I transfer my number into shorter number or string with some method?
3
by: Gospill | last post by:
Hi Guru, If I have string like "0D76" for example, it is actually a 0x0D76 in hex format. How can I convert the hex string 0D76 into decimal value ? So that I will get decimal value 3446 ...
5
by: Senna | last post by:
Hi, Have a symmetric encryption method that returns a base64 string. I then get the hex representation of that string with the code below public static string Base64ToHex(string input) {...
4
by: Ping | last post by:
Hi, All, We can use BitConverter.ToString(byte) to a string, but how to get the byte from a string like "AD-A6-0D-1F"?
8
by: tim | last post by:
This is probably another newbie question...but... even after reading quite some messages like '..hex to decimal', 'creating a hex value' , I can't figure this out: If i do >>> m=66 >>> n=hex(m)...
9
by: =?Utf-8?B?ZGg=?= | last post by:
If there's bunch of hex numbers: 0xA6, 0xD9, 0x00, 0xAA, 0x00, and 0x62, how to construct a string ("string" in C#) with those hex numbers? Thanks!
0
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,...
0
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...
0
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.