Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string.Substring DOES NOT EXIST

Status
Not open for further replies.

CodingIsFun

Programmer
Apr 9, 2004
134
US
Anyone come across this.

here is my code:

using System;
using System.Net;
using System.Xml;
using System.Collections;

namespace test
{

public class string_test
{
public string string_test(string t)
{
return t.Substring(1,1);
}
}
}

I get the error t.Substring does not exists
In the command window if I type ? t it returns the string content. If I do the same in the command window t.Substring(1,1) I get the same error.

Am I missing a reference to the string functions.

thanks in advance..
 
where have you initialzed the string t?

try this



string t="abcd";
public string string_test( t)
{
return t.Substring(1,1);
}
 
what chmohan is saying is, make sure the string being passed in is not null.

The string functions are found directly in the System reference.
 
Sorry I should have been clearer in my message,thats what i meant:)
 
Thanks for the help chmohan. The code that I posted is not what I am using, I just posted it up there so peeps can get an idea of what imnports I am using. I have spent an hour trying to figure out why the Substring and Remove functions do not exist.

basically I am trying to perform a Substring function on a string and it is giving me a silly runtime error.

here is some better code

using System;
using System.Net;
using System.Xml;
using System.Collections;

namespace test
{

public class string_test
{

public string_test()
{
}

public string string_sub_function(string t)
{
return t.Substring(1,1);
}
}
}

I make the instance then call the function
string_test substring_me = new string_test();
string work_please = substring_me.string_sub_function("eval");

bare with me I am not testing this as I go, so if there is a typo ignore it. the issue is I get a runtime error when it comes to the t.Substring(1,1). It says t.Substring does not exist. The Replace function does the same thing as well. When I run the command line ? t it returns "eval", so I know the string is there.

thanks in advance...
 
while t is in scope and I have created a break point on it.

I type ? t in the command window and it returns "eval"
when I type t.Substring(1,1) or t.Replace("-","") it tells me that they don't exist. I use the intellisense in the command window so I know its not case sensitivity. This is becoming a big pain in the arse. It's almost funny.

thanks for the help
 
How long is the string you're trying to substring? You can't get 10 characters out of a 5-character long string.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 

Thanks Chip, that is not an issue, the function is always passed a string of 100 characters. If there is no data or the parameter string is null the function is not called
 
Okay just to test try this

public string string_sub_function(string t)
{
string sTest= t.Substring(0,1);
return sTest;
}
 
public string string_sub_function(string t)
{
string sTest="String is empty";
if(t.Length>0)
{
sTest= t.Substring(0,1);
return sTest;
}
else
{
return sTest;
}

 
I think there is another explanation

maybe you need to try String instead of string
or you can also try t.ToString().Substring()
 
chmohan, that didn't work either.

I did a test, while I don't get a runtime error, I can't view the value in the quick watch window.
 
I tried the t.toString() before I posted this and it gave me the same error. Im going to try restarting my computer. LOL..
 
why are u trying to use quickwatch? Try MessageBox.Show and see if u get a value:)
 
Here is what I get in the Command Window. This is pretty funny:

? detail
"***"
? detail.Substring(1,1)
error: 'detail.Substring' does not exist
 
I get the same output as you in the command window, but no runtime error. Messagebox.show displayed the value correctly.

 
the
error:'detail.Substring' does not exist

is the runtime error

I get the same for any string function.

I restarted my computer so it had nothing to do with the state of my computer.


? detail
"***"
? detail.ToString
error: 'detail.ToString' does not exist
? detail.ToString()
error: 'detail.ToString' does not exist

There was another person in here that had the same problem a while ago, but they never posted if they found the issue.

thanks again for all your help guys/gals



 
I guess this is just one of those stupid things that VS Studio has to fix.

Thanks to everyone for your help today. Happy Friday :).
 
Maybe you've got a corrupt mscorlib.dll in your GAC. Try uninstalling/reinstalling the .net framework and see if that fixes it up.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top