String and platform issue

  • Thread starter Thread starter Ken
  • Start date Start date
K

Ken

HI:

I'm running an application on either Win2K or Win98. It always works fine
on Win2K but on Win98 the String.IndexOf method always returns -1. Code is
found below. I cut out all the code that has no bearing on what is
happening so it might look a little weird. The offending line is in the
ExtractMessageFragment method.

Does anyone know why there is a difference. I'm running the 1.1 version of
the framework on both OS's and building the application on my Win2K machine
with Visual Studio 2003.

Thanks

Ken

private void LoadMessages ( )
{
String line;

line = "This is some text and some more text then we will find Last
Modified On: 07/18/2003";

this.ExtractMessageFragment ( ref line );
this.tbNews.Text = line;

} // end LoadMessages

private void ExtractMessageFragment ( ref String line )
{
DateTime CurrentDate = DateTime.Now;
DateTime MsgDate;
Int32 SavePos = 0,
DaysToView = 180;

Boolean Found = false;

do
{
// This line always returns -1 under Windows 98
SavePos = line.IndexOf ( "Last Modified On:", SavePos + 1 );

if ( SavePos == -1 )
{
line = "Message File Error";
break;
}

MsgDate = DateTime.Parse ( line.Substring ( SavePos + 18,
10 ) );

if ( CurrentDate.Subtract ( MsgDate ).Days <= DaysToView )
{
Found = true;
}

} while ( !Found );

if ( Found )
{
line = line.Substring ( SavePos - 19 );
}

} // end ExtractMessageFragment
 
Hi Ken,

Thanks for your post. Based on my experience and research, I did not find
any known issue about this problem. I am building a Windows 98 system with
..NET Framework 1.1 to check this issue. In the meantime, I suggest you to
change the code as the following and check the result.

String strTemp = "Last Modified On:";
SavePos = line.IndexOf ( strTemp, SavePos + 1 );

Have a nice day! :)

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Sorry guys for causing you some unnecessary research.

I found the issue. I'm running Windows 98 under VMWare Workstation and the
date on the virtual machine was set to 2022. So the date test in the do
loop never had a found condition so the IndexOf ran out of string to test,
hence it returned -1. After setting the date correctly all is well.

Again sorry for the confusion.

Ken
 
Hi Ken,

Thanks for your update. I am glad to hear that the problem has been
resolved.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top