在字符串vb.net中查找数字

时间:2012-11-16 13:19:12

标签: asp.net sql vb.net

sql列中的数据,如

BLT Salad $4.50 Ham N Cheese Panini w/Chips or Soup  $3.99 Chicken Noodle Soup

我想在价格之后添加<br />。 (价格可能会改变,但$总是在那里)就像那样

BLT Salad $4.50
Ham N Cheese Panini w/Chips or Soup  $3.99
Chicken Noodle Soup

无论如何在价格之后的(。)之后的两个字符之后添加新行或者在($)之后添加4个字符? 谢谢

2 个答案:

答案 0 :(得分:3)

使用正则表达式,并假设数字总是$后跟一些数字,后跟a。后跟2位数:

Regex.Repalce(myString, "(\$\d+\.\d\d)", "$1<br />")

正则表达式的细分:

(      - Start capturing group
\$     - Match `$` sign
\d+    - Followed by one or more digit (replace with [0-9] if needed)
\.     - Followed by a .
\d\d   - Followed by two digits
)      - End capturing group

替换的细分:

$1     - Use the value of the first captured group
<br /> - Followed by <br />

答案 1 :(得分:1)

        Dim replaced = Regex.Replace(input, "(\$\d+\.\d{2,2})", "$1<br/>")