Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 13-Apr-14 16:38pm    
Split functions are already written, so you don't need to write one.
—SA
Maciej Los 13-Apr-14 17:15pm    
Sure!
My virtual 5!
Sergey Alexandrovich Kryukov 13-Apr-14 17:23pm    
:-)
Maciej Los 13-Apr-14 17:18pm    
Why to force in opened doors?
Please, read Sergey's comment!
Maciej Los 13-Apr-14 17:21pm    
Do you have only single value: R|2? Or do you have a list of values: R|2,A|3,R4,A|1?

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[^]
 
Share this answer
 
v2
I am not sure if it's entirely clear to me.

But what I understood, this is how it should be:

VB
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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Apr-14 16:39pm    
Voted 4. It's good to check up the length of split before using split(0) or split(1)...
—SA
Manas Bhardwaj 13-Apr-14 16:45pm    
Sure.

By the way, have you used ReSharper? It's quite awesome and I have been addicted to it.

It just tells you during writing code itself to check all possible null references etc.
Sergey Alexandrovich Kryukov 13-Apr-14 17:22pm    
No, but only because I don't like non-open source 3rd parties...
—SA
CHill60 13-Apr-14 17:27pm    
Virtual 5
Sergey Alexandrovich Kryukov 13-Apr-14 18:01pm    
Thank you.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900