<script type="text/C#" runat="server">
int? InStrCShape(string str1, string str2)
{
if (str1 == null || str2 == null)
return null;
return str1.IndexOf(str2)+1;
}
int? InStrCShape2(int? start, string str1, string str2, int? compare) {
int? result = null;
if (compare != null && start == null) {
throw new Exception("If you assign compare type,you must set start index!");
}
if (start != null && start < 1) {
throw new Exception("start index can not less than 1");
}
if (start == null){
start = 1;
}
if (compare == null) {
compare = 0;
}
if (str1 == null || str2==null ) {
return null;
}
if (str1.Length == 0) {
return 0;
}
if (str2.Length == 0) {
return start;
}
if (start > 1) {
str1 = str1.Substring(Convert.ToInt32(start));
}
int idx=str1.IndexOf(str2);
if (compare == 1) {
idx = str1.ToLower().IndexOf(str2.ToLower());
}
if (start > 1)
result = idx == -1 ? 0 : start + idx + 1;
else
result = idx == -1 ? 0 : idx + 1;
return result;
}
</script>
<%
string SearchString ="XXpXXpXXPXXP";
string SearchChar = "P";
int? l = 0;
l = InStrCShape2(4, SearchString, SearchChar, 1);
Response.Write(l);
l = InStrCShape2(1, SearchString, SearchChar, 0);
Response.Write(l);
l = InStrCShape2(null, SearchString, SearchChar, null);
Response.Write(l);
l = InStrCShape2(null, SearchString, "W", null);
Response.Write(l);
l = InStrCShape(SearchString,"");
Response.Write(l);
%>