String Utilities

Count Substring

Counts how many times a substring appears in a string with optional case-insensitive matching. Access via MCP in Cursor or Windsurf, or REST at `/v1/string/count-substring`. Example: counting "cat" in "The cat sat on the cat mat" returns 2. Supports overlapping matches and Unicode strings.

API Endpoint

GET /v1/string/count-substring

Code Examples

curl "https://tinyfn.io/v1/string/count-substring" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/string/count-substring', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/string/count-substring',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's string tools:

{
  "mcpServers": {
    "tinyfn-string": {
      "url": "https://tinyfn.io/mcp/string",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I count substring occurrences case-insensitively?

Pass a case-insensitive flag parameter. The tool will convert both strings to lowercase before counting matches.

Does count substring handle overlapping matches?

By default it finds non-overlapping matches. Some implementations offer an overlap flag to count overlapping occurrences like 'aa' appearing twice in 'aaa'.

Can I use this MCP tool to analyze log files in Claude Code?

Yes, it's perfect for counting error patterns, specific timestamps, or repeated events in log analysis workflows within AI coding assistants.

What happens if the substring is empty or longer than the main string?

Empty substring typically returns 0 or error. Substring longer than main string returns 0 since no matches are possible.

Does it work with Unicode characters and emojis?

Yes, it handles Unicode strings correctly, counting multi-byte characters and emojis as single units when they appear in the substring.

Try Count Substring Now

Get your free API key and start using Count Substring in seconds.

Get Free API Key