Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Thursday, January 13, 2011

C# IndexOf String Examples

IndexOf methods:

First, here we note that there are four IndexOf instance methods. The first two methods find the first indexes. They scan through the characters from the left to right. The second two find the last indexes, and they go from right to left.

IndexOf:This method finds the first index of the char argument. It returns -1 if the char was not found.

IndexOfAny:This method finds the first index of any of the char arguments. It returns -1 if none are found.

LastIndexOf:This finds the last index of the char argument. It returns -1 if the char was not found.

LastIndexOfAny:This finds the first index of any of the char arguments. It returns -1 if none are found.

Example:
string Path: C:\Documents and Settings\Jitendra\My Documents\Visual Studio 2008\Projects\WebApplication5\WebApplication5\

string k = stem.Web.HttpContext.Current.Request.PhysicalApplicationPath;
int o ;
k = k.Remove(k.LastIndexOf("\\"));
o = k.LastIndexOf("\\");
string appName1 = k.Substring(o+1);

Example:- string strFileName;
string strFile = strFileName.Substring(strFileName.LastIndexOf("\\")+1);

Wednesday, January 12, 2011

Special Character check through javascript

//The IndexOf method can be used to check if one character is inside of another. For example, suppose you want to check an email address to see if it contains the @ character. If it doesn't you can tell the user that it's an invalid email address.



script type="text/javascript" language ="javascript" >

function checkSpecialCharacters() {

var str = "'!#$%^&;*()";
var txtUserId = document.getElementById('txtUserId').value;
var txtPassword = document.getElementById('txtPassword').value;
var txt = txtUserId + txtPassword;

for (var i = 0; i < str.length; i++) { var char1 = str.substr(i, 1) if (txt.indexOf(char1) > -1) {
alert('special character(s) are not allowed in loginid/password');
//alert(obj.getMessage(196));
return false;
}
}
}
/script>

Tuesday, January 11, 2011

DefaultView

//DefaultView:filter a limited number of columns from a table:
//Distinct Data in DataTable with the Field of roleid,roleName,abbreviation........


DataSet infoDS=new DataSet();
DataTable dTable = infoDS.Tables[0].DefaultView.ToTable(true, "roleid", "roleName", "abbreviation");

for (int i = 0; i < dTable.Rows.Count; i++) { if (dTable.Rows.Count > 0)
{
string _RoleId = dTable.Rows[i]["roleid"].ToString();
string _RoleName = dTable.Rows[i]["roleName"].ToString();
string _Abbreviation = dTable.Rows[i]["abbreviation"].ToString();
}
}

Compute with DataTable

DataTable Dtable=new DataTable();
DataColumn DColumn=new DataColumn("Salary",typeof(float));
DTable.Column.Add(DColumn);

DataRow DRow=DTable.NewRow();
DRow[0]=25000;
DTable.Rows.Add(DRow);

DRow=DTable.NewRow();
DRow[0]=30000;
DTable.Rows.Add(DRow);

float TotalSalary=(float)DTable.Compute("Sum(Salary)","");
Console.WriteLine(TotalSalary);

Saturday, January 8, 2011

Dropdown bind through xml

XmlDocument xml = new XmlDocument();
string s =Server.MapPath("XMLfILE.xml");
string list = "/catalog/book";
xml.Load(s);
XmlNodeList xn = xml.SelectNodes(list);
foreach (XmlNode eleSourceNode in xn)
{
string ID = eleSourceNode.Attributes["id"].Value;
string author1 = eleSourceNode["author"].InnerText;
DRPLIST.Items.Add(new ListItem(author1 ,ID));
}


//XMLFILE.xml

?xml version="1.0"?>
catalog>
book id="bk101">
author>Gambardella, Matthew /author>
title>XML Developer's Guide /title>
genre>Computer /genre>
price>44.95 /price>
publish_date>2000-10-01 /publish_date>
description>
An in-depth look at creating applications
with XML.
/description>
/book>

book id="bk111">
author>O'Brien, Tim /author>
title>MSXML3: A Comprehensive Guide /title>
genre>Computer /genre>
price>36.95 /price>
publish_date>2000-12-01/publish_date>
description>
The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.
/description>
/book>
book id="bk112">
author>Galos, Mike/author>
title>Visual Studio 7: A Comprehensive Guide/title>
genre>Computer /genre>
price>49.95 /price>
publish_date>2001-04-16/publish_date>
description>
Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.
/description>
/book>
/catalog>

Link for Asp.net Architecture(Isapi.dll,httpcontext,hpptmodule)

http://www.west-wind.com/presentations/howaspnetworks/howaspnetworks.asp

Boxing and Unboxing(Convert value type to ref type and ref type to value type.)

int Val = 1;
Object Obj = Val; //Boxing
int i = (int)Val; //Unboxing