473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

ASCIIEncoding.GetString method

I've run into a problem using this method that I have
been able to work around, but I think that there is a
more elegant way.

I create an array of 256 bytes and use the
SHBrowseForFolders API to retrieve a folder path into the
array. When I use the GetString method, the length of
the returned string is always 256, even if the actual
path length is only 10.

Right now, I step through the byte array and count the
number of 0's that occur, and then use the string's
Remove method to remove that equal number of characters
from the end of the string.

My question is: Does anyone know what the Unicode
value '0' tranlates into in ASCII? When looking at the
returned string value from GetString, whatever value the
Unicode 0 is translated into is still there, but not
visible.
Nov 15 '05 #1
2 6112
Paul K <sh*********@comcast.net> wrote:
I've run into a problem using this method that I have
been able to work around, but I think that there is a
more elegant way.

I create an array of 256 bytes and use the
SHBrowseForFolders API to retrieve a folder path into the
array. When I use the GetString method, the length of
the returned string is always 256, even if the actual
path length is only 10.

Right now, I step through the byte array and count the
number of 0's that occur, and then use the string's
Remove method to remove that equal number of characters
from the end of the string.
Why not just search for '\0' using IndexOf, and then call
myString.Substring (0, resultOfIndexOf) to get the result? Or search
for byte 0 before calling GetString, and call GetString with the form
which takes parameters to specify the first byte to decode and the
number of bytes to decode.
My question is: Does anyone know what the Unicode
value '0' tranlates into in ASCII?
0.
When looking at the
returned string value from GetString, whatever value the
Unicode 0 is translated into is still there, but not
visible.


Instead of looking at ait in the debugger, dump the values out (as
integers) to the console.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
Mattias:
Why don't you retrieve it directly into a string instead? How did youdeclare the BROWSEINFO struct?


At first, I chose to retrieve it into an array of bytes
because I know a little about C++ and the Win32 API, but
not a whole lot, and I was following some advice I was
given. After a little bit of checking around, I see that
the SHGetPathFromIDList needs a pointer to a buffer for
the path, but I am not able to create a pointer to a
string (according to the compiler, unsafe pointers or
references to managed types are invalid). I have my
BROWSEINFO struct declared as follows:

private struct BROWSEINFO
{
public int hwndOwner;
public int pidlRoot;
public byte* pszDisplayName;
public byte* lpszTitle;
public uint ulFlags;
public int lpfn;
public int lparam;
public int imImage;
}

Is there something that I'm missing? If so, I would
greatly appreciate any suggestions. Thanks!

Paul
Nov 15 '05 #3

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

Similar topics

1
by: Sulla | last post by:
I ran into an interesting "problem" the other day when I was working on a very simple zip code utility function. I have a table in Oracle with the following columns: zipcode, state, latitude,...
11
by: Crane Linkledder | last post by:
What is the difference, and when to use one over the other? Thanks
2
by: Randy Harris | last post by:
Anyone have a suggestion for trapping errors while using the ADO GetString method? I'm using: Dim varA varA = CurrentProject.Connection.Execute( _ "Select FOO From BAR Where Field =...
4
by: Dino Buljubasic | last post by:
Hi, I am using a function to hash a string value: public string generateMD5Hash(string input) { MD5 md5Provider; // MD5 provider instance // generate byte code for input byte inputData =...
2
by: wk | last post by:
Hi, I am reading a mp3 file's last 128 bytes and putting the text into string variables. What is happening is that the string is being stored with, probably some wrong encoding or character, and...
0
by: jdp | last post by:
I'm converting an asp.net 1.1 app to 2.0 and am having difficulty determining why ASCIIEncoding.GetString returns a different value in ..NET 2.0 than 1.1. The code is simple but I can't locate the...
3
by: Frank Milverckowitz | last post by:
Hi, Newbie question about SqlDataReader column value access... In java jdbc code to get a value from a table column we can pass the column name (instead of an int index or offset): String...
1
by: mikfrost | last post by:
I'm trying to read the exif info in a JPG image file. Reading the ImageDescription field (270) that contains "abcæåø" only reads the first 3 characters "abc". The field was written with ACDSee...
3
by: =?Utf-8?B?RGFu?= | last post by:
When I use the following code I get "???" in place of the non-Ascii character. Is there any way to fix the conversion or do I have to write a function to search for "???" and replace with another...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
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...
0
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
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...

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.