Loop through an array and find a partial string
4 answers
I don't really know C #. Here's a basic low-level approach in pseudocode:
function boolean contains_string(string haystack, string needle)
int needleIndex
int haystackIndex
for haystackIndex from 0 to haystack.length-needle.length
for needleIndex from 0 to needle.length
if haystack[haystackIndex+needleIndex] != needle[needleIndex]
break
end if
end for
if needleIndex == needle.length-1
return TRUE
end if
end for
return FALSE
end function
for each element in array
if contains_string(element, "ack")
new_array.push element
end if
end for
It almost certainly contains errors.
0
source to share