Hi Mike,
As for how to format a string value, generally , we can use the
string.Format method to perform simple format, as for our problem, we can
use the following code to format the string:
string num = "800555-1212";
string newnum =
string.Format("({0}){1}",num.Substring(0,3),num.Substring(3,num.Length-3));
Response.Write("<br>num: " + num);
Response.Write("<br>newnum: " + newnum);
Here is the reference on "String.Format" method in MSDN:
#String.Format Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemstringclassfor
mattopic.asp?frame=true
Also, we can also use Regular Expressions to do string search or
relacement, for example:
function
{
string num = "800555-1212";
string newnum = Regex.Replace(num,@"\d{3}",new
MatchEvaluator(this.Addbracket));
Response.Write("<br>NewNum: " + newnum);
}
protected string Addbracket(Match m)
{
if(m.Index == 0)
{
string x = m.ToString();
return "(" + x + ")";
}
return m.ToString();
}
You can find some other examples on using Regex in .net framework at the
following link
#Regular Expression Examples
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconregularexpressione
xamples.asp?frame=true
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx