Hi

How can I to count a string sequence inside other string

Example

1X21X2XX122X12

I need to do statistics on how often appears a sequence of three characters eg

1X2 ==>2
12X ==> 0
X12 ==> 2
X21 ==> 1
21X ==> 1
2X1 ==> 1

How can I to do it reading a text file and counting and summarizing ?