473,804 Members | 2,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASCIIEncoding.G etString 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
SHBrowseForFold ers 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 6134
Paul K <sh*********@co mcast.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
SHBrowseForFold ers 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.Substr ing (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.co m>
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 SHGetPathFromID List 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
4613
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, longitude. My method calculates the distance from a given zipcode to all zipcodes by doing the following: 1. select zipcode, latitude, longitude from zipcode_table;
11
5032
by: Crane Linkledder | last post by:
What is the difference, and when to use one over the other? Thanks
2
6321
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 = Value").GetString If no records are returned an error is generated. Is Resume Next the best (perhaps the only) way to handle those errors? Or is there a better way to do it?
4
6401
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 = ASCIIEncoding.ASCII.GetBytes(input);
2
1419
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 hence has a " in front, and i cant see the full string in VB 2005 express's debug mode. I have based this off an example from the web. I have spent a full day trying to debug this with a lot of different ways, and now am exausted with ideas.
0
1314
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 problem. If someone could point out my oversight, I'd greatly appreciate it. Thanks in advance! Dim md5Hasher As New MD5CryptoServiceProvider Dim encoder As New ASCIIEncoding Dim strHashedBytes As Byte() =
3
2835
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 strLastName = rs.getString( "LastName" );
1
1364
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 photo manager. // using the GetString method propItem = img.GetPropertyItem(270); img_desc = Encoding.UTF8.GetString(propItem.Value);
3
4921
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 character? Any help or suggestions would be greatly appreciated. Thanks Dan Dim plainText As String plainText = "tâ””he" Dim plainTextBytes As Byte()
0
9704
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
9572
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
10562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
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...
0
9132
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
7608
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
4282
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
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
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.