|
Your question is a little abstract, where does the string come from? As a rule, ansi characters are 1 byte, whereas unicode characters are 2 bytes. So you could simply use sizeof() to determine the string type.
|
|
|
|
|
If you're lucky, your Unicode text will start with a Byte-Order Mark byte sequence. If the text is UTF-16LE, it will start with the bytes 0xFF 0xFE in that order. If it is UTF-16BE, it will start with 0xFE 0xFF in that order, which will require you to swap the bytes to interpret it correctly with Windows functions. If it starts with 0xEF 0xBB 0xBF, it's UTF-8.
None of these encodings require the use of the Byte Order Mark. If it's not present, and you don't know the encoding of the string, I'm afraid the only method is to guess. Windows offers a function IsTextUnicode which can do this guesswork, but it can be fooled, with sometimes embarrassing results: see here[^] for one example.
Best practice is always to mark a protocol payload or file with the character set or encoding it was written in.
|
|
|
|
|
Hi
I have the following problem .
I have a CString csBuffer ;
At tun time , this csBuffer gets unicode and ansi values alternatively . The value is only numbers.
For example
At one time csBuffer holds "1234" and another time it holds "1.2.3.4" .
So when the value is 1.2.3.4 , WideCharToMultiByte works fine and we get a ansi string "1234".
But when the value is 1234 , WideCharToMultiByte should not be called .
So after your suggestion I did the following
int nFlags=IS_TEXT_UNICODE_SIGNATURE;
if (::IsTextUnicode(csBuffer,csBuffer.GetLength(),&nFlags))
{
..message box "Its a unicode string"
}
But in both the cases IsTextUnicode did not succeed .
What can I do now ?
In fact I am a newbie when it comes to uncode stuffs ...
Please help me ...
Dharani
redindian
|
|
|
|
|
You can't. If I give you a bunch of bytes that end with 0, there's no way to be 100% sure what encoding was used to produce that string. As Mike said, you can call IsTextUnicode() but don't expect perfect accuracy. If you need 100% accuracy, you need to specify the encoding separately from the data.
|
|
|
|
|
Hi
I have a CString which holds unicode / ansi values alternatively .
For example ..csBuffer = "1.2.3.4"; and csBuffer="1234";
I need to find a way to differentiate between both the occurances .
IsTextUnicode() did not succeed when I passed csBuffer to it.
Please advise me
redindian
|
|
|
|
|
hi all
i have developed a MFC app in VS2003, recently upgraded to VS2005
however when i send out my updated exe to customers, a message box pops up saying to re-install the application
so I have updated my deployment application to vs2005, but when this trys to install, it wants to install .net framework 2.0
i dont need to use the .net framework so i dont know why it trys to install
even if you let it update the .net framework after it has installed, i still get a message box pop up asking to re-install the application
im pulling my hair out here
does anyone have any ideas ?? or seen this type of thing before ?
thanks
Si
|
|
|
|
|
Hi Guys,
This question I asked earlier, but I could nt continue,
I want to make it clear, Is there any API by which we can know the local drives of our system ( A:, C:, D: etc )?
Please do reply guys.
Thanks in Advance
Velayudhan
|
|
|
|
|
velayudhan_raj wrote: This question I asked earlier, but I could nt continue,
I want to make it clear, Is there any API by which we can know the local drives of our system ( A:, C:, D: etc )?
Please do reply guys.
GetLogicalDriveStrings();
|
|
|
|
|
It is not completely successful.
It is just returning a single drive's name
Actually I want all the name's of all drives in my system.
Thanks in Advance
Velayudhan
|
|
|
|
|
velayudhan_raj wrote: It is not completely successful.
It is just returning a single drive's name
Actually I want all the name's of all drives in my system.
You should first read the documentation carefully
Quote from MSDN...
lpBuffer
[out] Pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, that end with a second null character. The following example shows the buffer contents with <null> representing the terminating null character.
c:\<null>d:\<null><null>
End quote...
I guess you are trying to assign to a string which terminates where it finds a null character, hence you are not able to get the whole drives.
|
|
|
|
|
Dear Velayudhan,
I am Listing in LisBox, u can display it in any control.
Here is the Code.....
unsigned long driveList = GetLogicalDrives();
char drivePathName[] = " :\\";
CString drive;
for(int i = 1;i<26; i++) //u can give no of drives in your system
{
if(0x01 & (driveList >> i))
{
drivePathName[0] = 'A' + i;
drive.Format("%c",drivePathName[0]);
m_List.AddString(drive);
}
}
With Best Regards
Vidya
S/W Developer,
AnnetSite,Mumbai
|
|
|
|
|
How to use this function
<br />
char *m_Name=new char[256];<br />
DWORD Lenght=255;<br />
GetLogicalDriveStrings(Lenght,m_Name);<br />
...<br />
...<br />
-- modified at 10:25 Wednesday 6th September, 2006
|
|
|
|
|
WhiteSky wrote: How to use this file
What file?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
function
|
|
|
|
|
Fair enough. But the OP already knew how to use the function. He was troubling parsing the resulting buffer.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Each drive letter is separated by a nul character. Try:
char szDrives[105] = {0};
GetLogicalDriveStrings(sizeof(szDrives), szDrives);
char *pToken = szDrives;
while (*pToken != '\0')
{
cout << pToken << endl;
pToken += 4;
}
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Is There any short way to remove some lines from a file say there is a file called
Hello.dat contains 5000 lines
1) In that i just want read first 200 lines
2) Preform some operation
3)remove them i.e. 200 lines if the operation is proper //This is the problem
Some efficient was i.e. without creating another file i.e. new file
Payal
|
|
|
|
|
payal335 wrote: Some efficient was i.e. without creating another file i.e. new file
you have too make a new file for this.. there is no other option!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
payal335 wrote: Is There any short way to remove some lines from a file say there is a file called
Hello.dat contains 5000 lines
1) In that i just want read first 200 lines
2) Preform some operation
3)remove them i.e. 200 lines if the operation is proper //This is the problem
CFile::SetLength is one option, but you will have to do some additional work like counting the number of lines ( in your case 200 ).
|
|
|
|
|
Unfortunately, it seems the Operating System does not allow shortening of a file by removing data at the beginning. It only allows truncation of the tail. Therefore I think it is not possible to solve your problem without read and write operations (on the same or two files).
But I would consider the following approach. The first value of your file should be reserved: it will contain the position of the first line that should be read. After you read your 200 lines, simply rewrite the first value. These lines are still in the file, but are ignored on next operations.
So you have to deal with GetPosition and Seek members of CFile .
Instead of storing the position in the same file, you can store it in a separate file or in memory.
This way the file will grow when you append new lines, therefore you should really remove unneeded head lines periodically.
I hope this helps.
|
|
|
|
|
Thank you all for putting u r valuable time
payal
|
|
|
|
|
Hi,
I have data as log file, then i want to display that data in tabler format. so how can i do in my vc++ application.
Also I want to use bar chart and it should be support event. so what kind of chart control can I use.
please reply me if anybody know.
partha.s@papyrus.ne.jp
bye
parthasarathy
|
|
|
|
|
victorsarathy wrote: so what kind of chart control can I use.
please reply me if anybody know.
try google[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi All,
I am unable to work out the reason for the extra consumption of memory in the following code. This is just some code I was experimenting with. I am using the winldap libraries.
void TestInitialisation()
{
//LDAP* ldap = ldap_open(NULL, NULL);
LDAP* ldap = ldap_init(NULL, NULL);
if(ldap)
{
//ldap_set_option(ldap, LDAP_OPT_ROOTDSE_CACHE, LDAP_OPT_OFF);
//ldap_set_option(ldap, LDAP_OPT_CACHE_ENABLE, LDAP_OPT_OFF);
ldap_unbind(ldap);
}
else
assert(false);
}
The lines that I have commented are the options that I have tried, but they dont seem to make any difference. I also noticed that consequitive calls to TestInitialisation() will result in a leak too, but the number of calls to get a leak happening is not consistent. I found it useful to write up a small dialog application with a button press event that called TestInitialisation().
I would appreciate any ideas and help on this.
Thanks,
|
|
|
|
|
Is this code in a loop? if so did you remember to call ldap_unbind() . Each time you call ldap_open() you are creating a new handle, so unless you close it you will have a handle leak. You could also try adding static to the ldap_open() line, which would cause it to only be called on the first loop.
|
|
|
|