asp中对分子式中的下标的解决

来源:百度知道 编辑:UC知道 时间:2024/06/25 22:04:45
自己做一个化学的产品库,碰到一个问题.如何在数据库调用出来的一个化学式中,把那些数字用下标显示出来.
要用asp语言.
我只知道php
<?php

if($product_info['molecular_formula']!=""){echo '<tr><td class="productTitle">Molecular Formula:</td><td class="productDescription">';}

$molec = preg_split('//', $product_info['molecular_formula'], -1, PREG_SPLIT_NO_EMPTY);
foreach($molec as $key){
if($key==1 or $key==2 or $key==3 or $key==4 or $key==5 or $key==6 or $key==7 or $key==8 or $key==9 or $key=='0'){
echo'<sub>'.$key.'</sub>';
}
else{
echo $key;
}
}
if($product_info['molecular_formula']!=""){echo '</td></tr>';}
?>

谁能告诉我asp该怎么写.
<sub>这个我是知道的,我的意思是每串分子式都是从数据库中取出来的.格式如C194H295N53O58S1,我是要在前台显示的时候,凡是1-9的数字都要用下标,英文还是原样.就是有的判断,凡是符合1-9的数字都要用

用正则表达式是最佳选择,不过这个东西没学过比较麻烦。

你提供的PHP代码很傻瓜。也可以用一个很傻瓜的ASP函数:

function sub_str(str)
for i=1 to len(str)
tmp=mid(str,i,1)
if tmp=数字 then tmp="<sub>"&tmp&"</sub>"
sub_str=sub_str&tmp
next
end function

if tmp=数字 then 这里如何判断它是不是1234567890很简单,不用再写了吧?自己搞定。