Current time: 07-21-2017, 04:32 AM Hello There, Guest! Register

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

SmG Moderators
Posts: 741
Threads: 67
Joined: Feb 2014
Reputation: 23
Location: Summoners Rift
Evolve: raqsrx
Steam: flashtm_ FlasH#1774
LoL: Fl4sHy
League of LegendsHalo God
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: 05-06-2017, 02:52 PM by SmG FlasH™.)
05-06-2017, 02:50 PM
Find Reply
Online SmG Dragonrage

Royal Dragon
SmG Captain
Posts: 3,754
Threads: 203
Joined: Aug 2012
Reputation: 6
Location: Atlantis
Steam: Dragonrage Dragonrage#1671
LoL: SmG Dragon
Gavel of TrinityLeague of Legends
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]
[Image: graphic.png]
Do not meddle in the affairs of Dragons, for you are crunchy and taste good with ketchup!
05-08-2017, 01:00 AM
Website Find Reply

Forum Jump:

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