Click here to Skip to main content
14,696,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here Is my Code. And error of 'object doesnot contain a defination of substring' in SubString. please answer me please

if (phones_done.IndexOf("~" + rs["PhoneID"] + "~") + 1 == 0)
{

phone_string += " (" + rs["number"].Substring(0, 3) + ") " + rs["number"].SubString(3, 3) + "-";
phone_string += rs["number"].Substring(6) + " (" + rs["description"] + ")" + Environment.NewLine;

phones_done += "~" + rs["PhoneID"] + "~";
}
Posted
Comments
Ralf Meier 11-Jun-15 6:56am
   
What kind of type is rs[] ?
Perhaps you should use rs["number"].toString.subString(xy) if your object is convertible to String ...
[no name] 11-Jun-15 7:15am
   
You can substring a string, not an array.
Richard MacCutchan 11-Jun-15 7:17am
   
rs["anyname"] is an object, not a string, so does not contain such a method. You need to convert the object's value to a String first.

1 solution

The Substring function only works on strings - and (assuming rs is a RecordSet of some description) it will return objects. Try this:
phone_string += " (" + rs["number"].ToString().Substring(0, 3) + ") " + rs["number"].ToString().SubString(3, 3) + "-";
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900