Current time: 22 Oct 2017, 08:01 AM



Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Contributor: FlasH™Help with C#
Offline SmG FlasH™

Moderator
Moderators
*****
Posts: 1,140
Threads: 75
Joined: Feb 2014
Reputation: 48
Location: Summoners Rift
Steam: flashtm_
Battle.net: FlasH#1774
LoL: Fl4sHy
Halo GodCrystal DonatorSmooth
#1
Help with C#

So I'm working on a ChatApp which uses Tcp Clients and Tcp Listeners. 

So basically, I use NetworkStream to transfer data between the server and the client. The data is transferred in Bytes (byte []) and converted to String and displayed.
I use Encoding.ASCII.GetString() to convert it from bytes to String.

The problem is that when I convert bytes to string, the string contains null spaces, so I can't append text/ get substring of it.

Would be helpful if anyone can suggest a way to remove the null spaces or having the byte array size set to size of the string (in bytes) when receving from a stream.

Thanx in advance.

TLDR: Suggest a way to remove null spaces from string which use an encoder to convert byte array into string since data is transferred through networkstreams
[Image: 9o5goym4eq15sm5zg.jpg?size_id=5]
EvolveHQ: raqsrx           LoL: Fl4sHy           Steam: flashtm_
(This post was last modified: 06 May 2017, 02:52 PM by FlasH™.)
06 May 2017, 02:50 PM
Find Reply
Offline «SmG» Dragonrage

Royal Dragon
Administrators
*******
Posts: 4,074
Threads: 226
Joined: Aug 2012
Reputation: 28
Location: Atlantis
Steam: Dragonrage
Battle.net: Dragonrage#1671
LoL: SmG Dragon
Gavel of TrinityLeague of LegendsProgrammerCoolCrystal Donator
#2
RE: Help with C#

I think null characters get translated to \0 in c#. So you should be able to use the replace function. Like string mystring = input.Replace("\0", string.Empty);
[Image: mla7mw8hs3u0g9czg.jpg?size_id=5]
Do not meddle in the affairs of Dragons, for you are crunchy and taste good with ketchup!
08 May 2017, 01:00 AM
Website Find Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)
MyBB Theme by: CrystalThemes
Edited by: Wires