3
I need to do a function that returns the Length of a part of the string that is both suffix and prefix. So: Given the string: abbabba, the answer would be 4, because that would be:
Prefix:
a ab abb abba abbab abbabb
Suffix:
a ba bba abba babba bbabba
Logo Abba is both prefix and suffix. How do I do this?
I started like this and I can’t and I only have 10 more minutes.
public int teste(string nome)
{
string[] pre = new string[nome.Length];
string[] suf = new string[nome.Length];
for (int i = 0; i < nome.Length - 1; i++)
{
pre = nome[i].ToString();// Erro aqui
}
}
Do you have a goal? Or is the idea purely didactic?
– Leonel Sanches da Silva
I’m doing a test and I can do research on the test so there’s nothing fraudulent.
– pnet
I don’t know what the c# code would look like, but you can count the string lenght, do one for creating an array for the prefix and another for the suffix with each of the variations as shown in the question and then compare the two to get the values that are present in the two. In the end just take what has the largest lenght and you will have your (su)prefix.
– RodrigoBorth
It’s not the longest length, but the ones that are equal, then yes, I take that length.
– pnet
only count the same then, instead of the greater length as @Rodrigoborth said
– Pedro Laini
That’s exactly my question. I did an edit on the post.
– pnet
in the end you can take the lenght of all and check which is the highest and return the value
– RodrigoBorth
"I’m taking a test and I can do research" - this is not research.
– dcastro