Forum Moderators: open

Message Too Old, No Replies

Displaying phone numbers with alphabetic characters

         

hadiz

9:12 pm on Jul 30, 2008 (gmt 0)

10+ Year Member



Hi there,

I'm trying to work out a way to display alphabetic characters that occassionally appear in phone numbers (for instance, 866-555-BIKE). They way I have it setup now they are simply ignored. Here's what I currently have:

<%# String.Format("{0:###-###-####}", Convert.ToDecimal(DataBinder.Eval(Container.DataItem, "ItemValue").ToString().Replace("-","")))%>

I'm not trying to convert the alpha characters to numbers or anything, just display them.

I'd appreciate any pointers.

marcel

4:21 am on Jul 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried removing:
Convert.ToDecimal()

marcel

5:05 pm on Jul 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've looked into it further, and I don't think it is possible to format it with # (which is a digit placeholder)

You could use the following:


<%
string myString = (DataBinder.Eval(Container.DataItem, "ItemValue").ToString().Replace("-",""));
response.write(myString.Substring(0, 3) + "-" + myString.Substring(3, 3) + "-" + myString.Substring(6, 4));
%>