RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Uncomprehendable C# problem in data output pattern

Uncomprehendable C# problem in data output pattern

C# is just needlessly pissing me off, now. What part of:

Code:
extrarow = (((ASCIIstring.Length % 16 > 0))?(1):(0));
rows = (int)(ASCIIstring.Length / 16) + extrarow;
maxrows = rows;
			

String tempHexValue;
String tempHexString;
String tempASCIIString;
			
characters = hexstring.Length;
Console.WriteLine("Total Characters: {0}",characters);

for(int i = 0; i < maxrows; i++)
{
	Console.WriteLine("Characters: {0} Rows: {1} Maxrows: {2}", characters, rows, maxrows);
	if (characters < 48)
	{
		Console.WriteLine(hexstring.Substring((3 * 16) * i, characters) + "\n\n");
	}
	else
	{
		Console.WriteLine("Start: {0} Finish: {1} Difference: {2}", (3 * 16) * i, (3 * 16) * (i + 1), (3 * 16) * (i + 1) - (3 * 16) * i);
		Console.WriteLine(hexstring.Substring((3 * 16) * i, (3 * 16) * (i + 1)) + "\n\n");
		characters -= 48;
		rows -= 1;
					
	}
}

Could could EVER produce the following:

Code:
Total Characters: 186
Characters: 186 Rows: 4 Maxrows: 4
Start: 0 Finish: 48 Difference: 48
80 77 74 66 00 00 00 00 00 00 00 00 00 00 00 00


Characters: 138 Rows: 3 Maxrows: 4
Start: 48 Finish: 96 Difference: 48
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 73 64 00 00 00 00 00 00 00 00 00
 00 00 00 00 00


Characters: 90 Rows: 2 Maxrows: 4
Start: 96 Finish: 144 Difference: 48

And STILL tell me my substring call is out of bounds?! Notice that the values are start substringing at 96 and finish at 144, max characters being 186. Out of bounds WHERE?

Most importantly, what +1 incremental for loop could result in two lines of data on the same line when I have two endlines at the end of the string? Simply ludicrous.
 

Kamron

Knight
You are not showing enough of the script..... where did hexstring come from, and what is it?

Although I think you need

Code:
hexstring.Substring((3 * 16) * i, (3 * 16) * (i + 1) - (3 * 16) * i)
 
Joke's on me. I thought that String.Substring was Substring(start, end) when it was actually Substring(start, length), or at least my math was so.

I'm such an asshat, thanks.
 
Top