如何在VB.Net中编写Split函数 [英] How to write a Split function in VB.Net
问题描述
你好,
我有一个隐藏的字段值,它保存其他Jquery函数值,文本框中的值用'|'符号分隔,如'R | 2 ','A | 3'等,其中字母R和A属于数据库中名为pay_category字段的列,2,3是我在文本框中输入的值。现在条件是如果Pay_Category是A,那么该值应该发送到Amount列,如果是R,则该值应该发送到小时。如何使用VB.net中的split函数或任何其他方式实现此目的。谢谢。
Hello,
I've an hidden field value which holds other Jquery function value and a value from textbox separated by '|' symbol like 'R|2', 'A|3' etc, where the alphabets R and A belongs to column called pay_category field in database and 2,3 are values that I entered in the textbox. Now the condition is if Pay_Category is A the value should be sent to Amount column and if it is R the value should be send to hours. How to achieve this using split function in VB.net or by any other way. Thanks.
推荐答案
请看看你的问题的评论。
谢尔盖是对的!
我建议你看看这个:分裂方法 [ ^ 。 Split函数可以接受用于分隔子字符串的Unicode字符数组。结论:您可以根据许多字符(A,R等)拆分字符串;)
另一方面,可以在服务器端拆分文本将其与数据库值进行比较:使用逗号分隔值参数字符串SQL IN子句 [ ^ ]
Please, see the comments to your question.
Sergey is right!
I'd suggest you to see this: Split Method[^]. Split function can accept an array of Unicode characters that delimit the substrings. Conclusion: you can split string based on many characters (A, R, etc.) ;)
On the other hand, it is possible to split text on server side to compare it with database values: Using comma separated value parameter strings in SQL IN clauses[^]
我不确定这对我来说是否完全清楚。
但是据我所知,这应该是这样的:
I am not sure if it's entirely clear to me.
But what I understood, this is how it should be:
Dim input As String = "R|2"
Dim split As String() = input.Split(New [Char]() {"|"})
If split(0) = "A" Then
amount = split(1)
ElseIf split(0) = "R" Then
hours = split(1)
End If
这篇关于如何在VB.Net中编写Split函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!