# How to count string occurrences in string?

I'm trying translate this tiny Python program into Snap!
Is there any function to count string occurrences in other string?
If not, what could be the best way to do the new block? Try it with strings or to built a list with the datas?

import random

for i in range(1000):
cara_o_cruz=str(random.randint(0,1))

print('Han salido 6 cruces seguidas '+str(ocurrencias)+' veces.')
print('Han salido 6 caras seguidas '+str(ocurrencias)+' veces.')



Really cool. I don't quite understand why it works but it works
I will look closely at the operation of the split block. Thanks.

The split block takes a string and makes a list of substrings before and after each instance.
(split [first$second$third] by [\$]) makes a list with first, second, and third.
(split [The quick brown fox jumps over the lazy dog.] by [e]) makes a list with:
Th,  quick brown fox jumps ov, r th, and  lazy dog..
For each instance, there is a substring just after it.
There's also a substring at the beginning, so you have to subtract 1.

I see. Thanks again for the explanation.

Yep.I often do that in js to calculate if there is a string inside another string.

<!--Search Bar-->
<input id='search' required placeholder='Search...'>
<button type='submit' onclick='submit();'>Search</button>
<div id='ifs'></div>
<script>
function LXD(f1,meth,url)
{
//Just for requests.
var xmlhttp;
if (window.XMLHttpRequest)
{
// Code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
{
{
f1(xmlhttp.responseText);
}
}
xmlhttp.open(meth,url,true);
xmlhttp.send();
}
const ITER_FILES=[
'/testy/dmk.html',
'/testy/index.html'
]
function submit(){
document.getElementById('ifs').innerHTML='';
for(it in ITER_FILES) {
i=ITER_FILES[it]
LXD(function(xml){
if(xml.split(document.getElementById('search').value).length>1){//<--Here!
document.getElementById('ifs').innerHTML+='<iframe src=\"'+i+'\" width=\"1000\"> </iframe>';
}
},'GET',i);
}
}
</script>