Hi,
I have a windows C# app which read data through socket from a C++ app in a
linux box. After a marshal a pointer and get an array of string ends with \0,
I did something like this
string s=new string(array);
s = s.Replace("\0","");
if(s == "ABC")
success
else
fail
However, if I did it in my test all in C#, it works. If I plug into the
production and start to listen to the linux box messages, it always fail. If
Studio's output window, I can see s becomes ABC~ instead of ABC.
Does anyone here know what is the most efficient way to solve this problem?
I do can iterate the array to detect \0, but I do want the most efficient way
since I am facing a very heavy traffic from that linux box.
Thanks a lot
Chris 6 1825
chrisben <ch******@discussions.microsoft.com> wrote: I have a windows C# app which read data through socket from a C++ app in a linux box. After a marshal a pointer and get an array of string ends with \0, I did something like this
string s=new string(array); s = s.Replace("\0",""); if(s == "ABC") success else fail
However, if I did it in my test all in C#, it works. If I plug into the production and start to listen to the linux box messages, it always fail. If Studio's output window, I can see s becomes ABC~ instead of ABC.
Does anyone here know what is the most efficient way to solve this problem? I do can iterate the array to detect \0, but I do want the most efficient way since I am facing a very heavy traffic from that linux box.
Well, your code is definitely removing \0 characters, so the rogue
character in s is something different. I suggest you print out its
Unicode value.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
chrisben <ch******@discussions.microsoft.com> wrote: I have a windows C# app which read data through socket from a C++ app in a linux box. After a marshal a pointer and get an array of string ends with \0, I did something like this
string s=new string(array); s = s.Replace("\0",""); if(s == "ABC") success else fail
However, if I did it in my test all in C#, it works. If I plug into the production and start to listen to the linux box messages, it always fail. If Studio's output window, I can see s becomes ABC~ instead of ABC.
Does anyone here know what is the most efficient way to solve this problem? I do can iterate the array to detect \0, but I do want the most efficient way since I am facing a very heavy traffic from that linux box.
Well, your code is definitely removing \0 characters, so the rogue
character in s is something different. I suggest you print out its
Unicode value.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thanks. Actually, I checked the input again and realize there is more than /0
in the input. That is a 5 byte array, after converting to char array, it
shows as below in debu window
{Length=5}
[0]: 65 'A'
[1]: 73 'B'
[2]: 89 'C'
[3]: 0 ''
[4]: 732 '˜'
Any idea about what is going on?
Thanks
"Jon Skeet [C# MVP]" wrote: chrisben <ch******@discussions.microsoft.com> wrote: I have a windows C# app which read data through socket from a C++ app in a linux box. After a marshal a pointer and get an array of string ends with \0, I did something like this
string s=new string(array); s = s.Replace("\0",""); if(s == "ABC") success else fail
However, if I did it in my test all in C#, it works. If I plug into the production and start to listen to the linux box messages, it always fail. If Studio's output window, I can see s becomes ABC~ instead of ABC.
Does anyone here know what is the most efficient way to solve this problem? I do can iterate the array to detect \0, but I do want the most efficient way since I am facing a very heavy traffic from that linux box.
Well, your code is definitely removing \0 characters, so the rogue character in s is something different. I suggest you print out its Unicode value.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Thanks. Actually, I checked the input again and realize there is more than /0
in the input. That is a 5 byte array, after converting to char array, it
shows as below in debu window
{Length=5}
[0]: 65 'A'
[1]: 73 'B'
[2]: 89 'C'
[3]: 0 ''
[4]: 732 '˜'
Any idea about what is going on?
Thanks
"Jon Skeet [C# MVP]" wrote: chrisben <ch******@discussions.microsoft.com> wrote: I have a windows C# app which read data through socket from a C++ app in a linux box. After a marshal a pointer and get an array of string ends with \0, I did something like this
string s=new string(array); s = s.Replace("\0",""); if(s == "ABC") success else fail
However, if I did it in my test all in C#, it works. If I plug into the production and start to listen to the linux box messages, it always fail. If Studio's output window, I can see s becomes ABC~ instead of ABC.
Does anyone here know what is the most efficient way to solve this problem? I do can iterate the array to detect \0, but I do want the most efficient way since I am facing a very heavy traffic from that linux box.
Well, your code is definitely removing \0 characters, so the rogue character in s is something different. I suggest you print out its Unicode value.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
chrisben <ch******@discussions.microsoft.com> wrote: Thanks. Actually, I checked the input again and realize there is more than /0 in the input. That is a 5 byte array, after converting to char array, it shows as below in debu window
{Length=5} [0]: 65 'A' [1]: 73 'B' [2]: 89 'C' [3]: 0 '' [4]: 732 '?' Any idea about what is going on?
It looks like you're potentially using the wrong encoding to convert
the data into characters, and also potentially you're not decoding the
right amount of data in the first place.
What does the code you're using to read from the socket look like?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
chrisben <ch******@discussions.microsoft.com> wrote: Thanks. Actually, I checked the input again and realize there is more than /0 in the input. That is a 5 byte array, after converting to char array, it shows as below in debu window
{Length=5} [0]: 65 'A' [1]: 73 'B' [2]: 89 'C' [3]: 0 '' [4]: 732 '?' Any idea about what is going on?
It looks like you're potentially using the wrong encoding to convert
the data into characters, and also potentially you're not decoding the
right amount of data in the first place.
What does the code you're using to read from the socket look like?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Broderick |
last post by:
I've got a problem with the RichTextBox control in .Net
where the garbage collector doesn't reclaim its memory
after I've finished with it.
My program adds a series of rtb's to the control array...
|
by: Timo |
last post by:
I am trying to get address of myStruct to a string array texts.
I am using M$ Visual C++ 6.0 (this is not OS specific question, though,
this code should also work on 16 bit embedded compiler ;)).
...
|
by: Chris Plowman |
last post by:
Hi all,
I was wondering if anyone can help me with a really annoying problem I have
been having. I made a derived datagrid class that will select the row when
a user clicks anywhere on a cell...
|
by: tangus via DotNetMonster.com |
last post by:
Hello all, I'm really struggling with getting some Active Directory code to
work in ASP.NET. Can you please provide assistance? I am executing the
following code:
Dim enTry As DirectoryEntry =...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm relatively new with C-programming and even though I've read about
pointers and arrays many times, it's a topic that is a little confusing
to me - at least at this moment:
----
1)...
|
by: brasilino |
last post by:
Hi Folks:
I've been looking (aka googling) around with no success.
I need a usability beyond 'pop()' method when removing an Array
elements. For example:
oName = new...
|
by: DJG79 |
last post by:
Hi all,
I am using an open source menu that i found and it works great, except
for one thing that when the web page is not scrolled to the very top
the drop down links will not stay visible. Has...
|
by: David |
last post by:
Hi,
I am trying to achieve the following:
1/ To have a standard form in an asp web page which has various
check boxes and radio buttons.
As a user selects a form item it updates a text box,...
|
by: Filemaxor |
last post by:
I have gotten my code to be able to allow people to add new text to a .txt document and able to call up files so the user can see whats in it. The problem i'm having is getting the for loop to work...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |