Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

STRING CONTAINS

Hi All,

I have a string and I want to compare if in ("A", "B", "C").
I try VariableA.Contains("A", "B", "C"), it does not work.

How could I do it using string.contains ?  


Or there are other ways to do it ?

Thank you.
Avatar of PagodNaUtak
PagodNaUtak
Flag of Philippines image

you can only compare it one at a time. Sample:

If variableA.Contains("A") then
      'Do something here
End if

If variableA.Contains("B") then
      'Do something here
End if

If variableA.Contains("C") then
      'Do something here
End if
Avatar of emi_sastra
emi_sastra

ASKER

VariableA.Contains(strToCompareVariable)

The strToCompareVariable is already "A", "B", "C", and I get it from a function.

Is there any simple ways to do it ?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of PagodNaUtak
PagodNaUtak
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you give me the value of VariableA and strToCompareVariable?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've got error :

Error      1      Expression of type 'String' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.       

Thank you.
Can you post the code?
This is the code that throw compile error.

Dim VairableA As String = "JosephOcena"
        Dim Search() As Char = "A,B,C"

        Dim result = (From letter In VairableA.ToUpper _
                     Where Search.Contains(letter)).Count

Thank you.
Add an Import statement for the System.Linq, System.Data.Linq, or System.Xml.Linq namespace to your code file. You can also import namespaces for your project by using the References page of the Project Designer (My Project).
-    Dim result = (From letter In VairableA.ToUpper _
                     Where Search.Contains(letter)).Count

What is letter here ?

Thank you.
Avatar of Nasir Razzaq
Do you mean

"A,B,C".Contains(VariableA)

?
I mean VariableA,contains(strToCompareVariable)

VariableA could be any string.
strToCompareVariable="A, B, C", yet strToCompareVariable could any string too.

Thank you.
Hi All,

Thank you very much for your help.