user793468
user793468

Reputation: 4966

format numeric string in html

I have a data in the following format

"1214423-034"

in html table, How can I format the string such that I only display everything after hyphen, so in this case only display "

034"

Is there any html function that I can use for this?

Thanks in advance.

Upvotes: 1

Views: 947

Answers (3)

NG.
NG.

Reputation: 6043

string foo = "1214423-034";
Response.Write(foo.Substring(foo.IndexOf("-") + 1));

Upvotes: 1

HatSoft
HatSoft

Reputation: 11201

Using Jquery

e.g. <div id="lblText" >1214423-034</div>

<script type="text/javascript">
$(document).ready(function(){
var element = $("#lblText").text().split("-");
});
</script>

Incase you decide to do in C#

string text = "1214423-034";

text = text.split("-").[1];

int number = 0;

bool result = Int32.TryParse(text, out number);

Upvotes: 1

worsnupd
worsnupd

Reputation: 174

You can accomplish this easily with Javascript using the indexOf() and substring() functions, like this:

<script type="text/javascript">
    var str = "1214423-034";
    var pos = str.indexOf("-");
    document.write(str.substring(pos + 1));
</script>

Upvotes: 2

Related Questions