Je cherche une fonction qui ajoute un string à un autre sur le premier 'match' entre les deux.
Exemple:
StringA = "azerty"
StringB = "tyuiop"
Match: "ty"
Resultat(StringA, StringB) = "azertyuiop"
Ça dit quelque-chose à quelqu'un ?
question : si
StringA = "azerty"
StringB = "zetyuiop"
Match: "ze"
alors "azetyuioprty" ?
dans la logique de ce que j'ai écrit au dessus oui, mais l'idée serait d'avoir une taille de match minimum (5, 10, 40 chars)...
Édit; si ce n'est même toute la fin du string.
je comprends pas ton match minimum.
sinon ceci marche bien :
String s = "azerty";
Console.WriteLine("The initial string: '{0}'", s);
s = s.Replace("ze", "zetyuiop");
Console.WriteLine("The final string: '{0}'", s);
en fait le match on le donne pas, l'idée c'est qu'il le trouve.
J'ai trouvé un raisonnements qui semble fonctionner avec ce que je cherche à faire faudra que je test ce soir. (pour un match de 3 minimum dans ce cas)
Le match est il automatiquement a la fin de la chaines de caractères et au début de l'autre ?
posA = position of match in StringA
posB = position of match in StringB
Si posA et posB alors
result = StringA[0,posA] + StringB[posB]
La plupart des langages ont une fonction pour trouver une chaine dans une autre chaine.
C'est en quel langage ?
Tu ne trouveras pas de fonction toute faite pour ce que tu veux faire, quelque chose de ce genre devrait fonctionner :
string StringA = "azerty";
string StringB = "tyuiop";
int MatchLength = 2; // Définit la taille de ton match
for(int i = 0; i <= StringA.Length - MatchLength; i++)
{
string Find = StringA.Substring(i, MatchLength);
if(StringB.IndexOf(Find) != -1)
{
string Final = StringA + StringB.Substring(MatchLength);
Console.WriteLine(Final);
}
}