How to get number of occurencies of specific element in IEnumerable

Hi. Does anyone know how to get number of occurencies of specific element in IEnumerable?
I have the string below and have to find out what is number of occurencies of string "CRAFORD MARK"
OIB: Matični broj: 11654684 Broj osobne: 11654684 Identifikacijski broj:
Id klijenta: 55 Naziv: BROKER BROKER Adresa: KK 81000 PODGORICA

OIB: NULL Matični broj: 5555 Broj osobne: - Identifikacijski broj:
Id klijenta: 989898 Naziv: BUDIMIR CICMIL Adresa: DJOKA MIRASEVICA 15 81000 PODGORICA

OIB: Matični broj: 2409980263005 Broj osobne: 765543533 Identifikacijski broj:
Id klijenta: 400110 Naziv: BULL AND BEAR Adresa: ULICA 81000 PODGORICA

OIB: Matični broj: 02708256 Broj osobne: - Identifikacijski broj:
Id klijenta: 555555 Naziv: BULL AND BEAR AD Adresa: MARKA MILJANOVA 46/14 81000 PODGORICA

OIB: Matični broj: 02708256 Broj osobne: - Identifikacijski broj:
Id klijenta: 39943 Naziv: CDA Adresa: X 81000 PODGORICA

OIB: Matični broj: 02320924 Broj osobne: - Identifikacijski broj:
Id klijenta: 177088978 Naziv: CRAFORD MARK Adresa: HAVELA 7

OIB: Matični broj: 72138 Broj osobne: Identifikacijski broj:
Id klijenta: 8771 Naziv: CRAFORD MARK Adresa: STALONE 5

OIB: Matični broj: 11778877 Broj osobne: Identifikacijski broj:
Id klijenta: 15282 Naziv: CRNOGORSKI TELEKOM AD PODGORICA Adresa: STUDENTSKA BB 81000 PODGORICA

OIB: Matični broj: 02289377 Broj osobne: - Identifikacijski broj:
Id klijenta: 205602 Naziv: ČAVLOVIĆ BALŠA Adresa: ANDRIJE PALTAŠIĆA 32 81000 PODGORICA

OIB: Matični broj: 2502985210023 Broj osobne: Identifikacijski broj:
Id klijenta: 2806991217977 Naziv: DABAR DABAR PROBNI Adresa: MOSKOVSKA 5 81000 PODGORICA

Hi @Olivera_Kalinic

Please try this,

If it is case sensitive (only match “CRAFORD MARK”)

System.Text.RegularExpressions.Regex.matches("inputstring","CRAFORD MARK").count.tostring

If it is case insensitive (matches ex: “CRAFORD MARK”,“Craford MARK”)

System.Text.RegularExpressions.Regex.matches("inputstring","CRAFORD MARK",regexoptions.ignorecase).count.tostring

Thanks

I’ve used this

System.text.regularexpressions.regex.matches(nizKlijenata.ToString,item.ToString).count,

but, as my input string nizKlijenata, is IEnumerable it doesn’t work.
When I print out nizKlijenata.ToString I get this result System.Linq.Enumerable+d__97`1[System.Text.RegularExpressions.Match]. How can I reach whole string of this IEnumerable format?

@Olivera_Kalinic what is stored in the nizKlijenata variable and where it is coming from?

Thanks

I get it with this Matches activity

String from the first post is stored in variable nizKlijenata, after above matches activity iz done.

Please try like this,

System.text.regularexpressions.regex.matches(nizKlijenata(0).ToString,item.ToString).count.tostring

Or

System.text.regularexpressions.regex.matches(nizKlijenata.FirstorDefault.ToString,item.ToString).count.tostring

Thanks

If I try like you suggested, I get this message

System.Linq.Enumerable+d__97`1[System.Text.RegularExpressions.Match]

We assume a flow similar to your screenshot
grafik

where you looking for any text between Naziv and Adresa with the matches activity
We do understand that afterwards the occurence of CRAFORD MARK is to count

had you tried following?

nizKlijenata.Cast(Of Match).Where(Function (m) m.toString.Trim.ToUpper.Equals("CRAFORD MARK") ).Count 

@Olivera_Kalinic have you tried this one ?

System.text.regularexpressions.regex.matches(item.tostring,nizKlijenata(0).ToString).count.tostring

Is this inside for each activity?
What is the value of item.tostring?

Thanks

When I use

item.ToString + System.text.regularexpressions.regex.matches(item.tostring,nizKlijenata(klijentBr).ToString).count.ToString (it goes through if loop, so I have to use klijentBr to iterate through it) I get 1 even though, for example, “CRAFORD MARK” has 2 occurencies…

@Olivera_Kalinic - After the matches activity please try

    nizKlijenata.count.tostring 

This will 2. Is this what you are looking for?

But I have to get count of all clients individually. For example, for “CRAFORD MARK” I have to get result 2, for client " BROKER BROKER" result would be 1, etc.
nizKlijenata.count.tostring will return count of all clients, won’t it?

thats why above was suggested

@Olivera_Kalinic can you share some screenshots of the workflow?

Thanks

@Olivera_Kalinic - i guess you are looking for Individual count of each of the items right??

Like BROKER BROKER = 1
CRAFORD MARK = 2
etc etc…

It works, thanks a lot :).

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.