Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

A Better Solution To My charToString Method?

$
0
0

Hiya,

 Please look at my code and tell me if there is a solution that is better, more consice, not cluncky like;

public static string charToString( int Count, BinaryReader BR )
{
	int j;
	char[] eBuff = new char[ 260 ];

	StringBuilder sb = new StringBuilder( Count );

	sb.Append( '#', Count );

	eBuff = BR.ReadChars( Count );

	for ( j = 0; j < Count; j++ )
	{
		switch ( eBuff[ j ] )
		{
			case '/':
			sb[ j ] = '\\';
			break;

			case ' ':
			sb[ j ] = '_';
			break;

			default:
			sb[ j ] = eBuff[ j ];
			break;
		}
	}

	return ( sb.ToString() );
}

As you can see, there is a few conversion for ASC space and ASC forward slash.  Below is a Hex dump snippet, the

highlight section is what the above method read/converts. There is 4 bytes prior to the ASC that gives the length.

 Any suggestion would be appreciated. As always, rudeness is not... So, dont. Thanks :)


Viewing all articles
Browse latest Browse all 31927

Trending Articles