Re: Convert a Widestring to an Ascii String?

Tech-Archive recommends: Fix windows errors by optimizing your registry




"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>

Marc,

Regardless, if you use the character array, then you can parse the
character array, looking for the null characters, and splitting the
strings apart that way.

Hey thanks, this works:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern uint GetPrivateProfileSection(string lpAppName, [In, Out]
char[] lpReturnedString, uint nSize, string lpFileName);
//
public static bool GetPrivateProfileSectionAsCommaText(string appName,
string fileName, out string section)
{
section = "";
uint MAX_BUFFER = 327670;
char[] sectionchar = new char[MAX_BUFFER];
if (!System.IO.File.Exists(fileName))
return false;
uint bytesReturned = GetPrivateProfileSection(appName, sectionchar,
MAX_BUFFER, fileName);
if ((bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0))
return false;
for (int i = 0; i < bytesReturned; i++)
{
if (sectionchar[i] != (char)0)
section += sectionchar[i];
else
{
if (i != bytesReturned - 1) section += ',';
}
}
return true;
}






.



Relevant Pages

  • Re: Substring
    ... Which is unfortunate because the null string will be holding on to a character array it doesn't need. ... As suggested in 2001 and 2005 Sun bug reports regarding this very behaviour of substring(...), if the implementation of substringdoes not change it would be helpful if the Javadoc for the method points out this behaviour. ...
    (comp.lang.java.programmer)
  • read bytes from file
    ... NextExecuteTime As Date ... ProcScheduler As String * 1 ... offsets and lengths contained in the TextOffset array. ... into a character array, but I have to define the character array size before ...
    (comp.lang.java.programmer)
  • Re: select specific capture device by name
    ... > I beleive that var.bstrval has the string that I need, ... IVC_BOARD_NAME is not a BSTR. ... and points to a Unicode character array. ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: How to match string for cell array strmatch() in Matlab
    ... Requires character array or cell array of strings as inputs. ... then I need to parse the textscan results using the strmatch but met ... If you just want to know if there is an 'a' but don't care where in the string it is, ...
    (comp.soft-sys.matlab)
  • Re: going through a string / char array and putting the bits in other variables
    ... > string or character array, and then reads through the string and takes ... > more varialbes and stuff but Im tryin to do it myself I just don't know ... > just functions to do this sort of thing, ...
    (comp.lang.cpp)