Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 12-04-2005, 03:13 PM   #1 (permalink)
 
Join Date: Oct 2002
Posts: 30
Send a message via ICQ to The One Divine
Default 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.
The One Divine is offline   Reply With Quote
Old 12-05-2005, 12:12 AM   #2 (permalink)
 
Join Date: Oct 2002
Age: 23
Posts: 4,689
Default

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)
XxSP1DERxX is offline   Reply With Quote
Old 12-05-2005, 01:14 AM   #3 (permalink)
 
Join Date: Oct 2002
Posts: 30
Send a message via ICQ to The One Divine
Default

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.

Last edited by The One Divine; 12-05-2005 at 01:18 AM.
The One Divine is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5