Current time: 29 Mar 2024, 07:53 AM



Help with C#
Away SmG FlasH™

Senior Member
Senior Member
******
10 Years of Service
Posts: 3,129
Threads: 102
Likes Received: 0 in 0 posts
Likes Given: 0
Joined: Apr 2013
Reputation: 141
Location: Summoners Rift
Halo GodCrystal DonatorSmoothThe BombDiscord WarriorGavel of Trinity
DiamondGamerProgrammerThanks From Cloud
#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: SPOILER_FlasH-1.gif]
(This post was last modified: 06 May 2017, 10:52 AM by FlasH™.)
06 May 2017, 10:50 AM
Find Reply
Offline SmG Dragonrage

Royal Dragon
Senior Member
******
11 Years of Service
Posts: 4,018
Threads: 206
Likes Received: 0 in 0 posts
Likes Given: 0
Joined: Aug 2012
Reputation: 38
Location: Atlantis
Gavel of TrinityLeague of LegendsProgrammerCoolCrystal DonatorLegendary
#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!
07 May 2017, 09:00 PM
Website Find Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)
SmG Gaming, © 2010-2024
Theme By: «SmG» Cloud
Edited by: «SmG» Wires