function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi All,
I need to find out the string contains in set of string.Please give me some example.
Thanks
Sai,
You can use containsAll method of set only if you are comparing two sets equality.
use contains instead
if(sub2.Contains(rec.Substring__c))
Eg:
set<string> mySet = new Set<String>{'abc', 'efg'};
system.debug('Test>>>> '+mySet.contains('abc'));
Can you please give an example on what you wanted to achieve?
i am trying to find the string from a set of string in apex.
like this
if(rec.Substring__c.containsAll(sub2))
where sub2 is set<String>
but above statement gives an error
To do that you will have to loop through the set and use a flag to determine if any value was not matched in the string
Boolean noMatch = false;
For(String s : sub2){
if(!rec.substring__c.contains(s))
noMatch = true;
}
if(noMatch = false){
//all values matched process here
Thanks Sam.
Sai,
You can use containsAll method of set only if you are comparing two sets equality.
use contains instead
if(sub2.Contains(rec.Substring__c))
Eg:
set<string> mySet = new Set<String>{'abc', 'efg'};
system.debug('Test>>>> '+mySet.contains('abc'));
All Answers
Can you please give an example on what you wanted to achieve?
i am trying to find the string from a set of string in apex.
like this
if(rec.Substring__c.containsAll(sub2))
where sub2 is set<String>
but above statement gives an error
Sai,
You can use containsAll method of set only if you are comparing two sets equality.
use contains instead
if(sub2.Contains(rec.Substring__c))
Eg:
set<string> mySet = new Set<String>{'abc', 'efg'};
system.debug('Test>>>> '+mySet.contains('abc'));
To do that you will have to loop through the set and use a flag to determine if any value was not matched in the string
Boolean noMatch = false;
For(String s : sub2){
if(!rec.substring__c.contains(s))
noMatch = true;
}
if(noMatch = false){
//all values matched process here
}
Thanks Sam.