![]() |
[QUOTE=CRGreathouse;226913]
[code]substring(string_to_search, string_to_find)={ my(s1=Vec(string_to_search),s2=Vec(string_to_find),good); for(i=0,#s1-#s2, good=1; for(j=1,#s2, if(s2[j] != s1[j+i], good=0;break)); if(good, return(1)) ); 0 };[/code][/QUOTE] is there a way to create 2 Vec() on the fly to read the parts around the string into and then put out the result of those 2 and the replaced word in between into another that you can return later the only thing with this idea I don't see happening is skipping ahead the length of the new word inserted and making the loop realize to go until the new end of the string. I know I'm annoying lol. |
got it partly in place now I need a way to get the string after s2 is found and I may have something closer to what is needed.
|
I can't understand you, but I'm glad my script seems to have been useful, either as inspiration or as a tool.
|
[QUOTE=CRGreathouse;229045]I can't understand you, but I'm glad my script seems to have been useful, either as inspiration or as a tool.[/QUOTE]
yeah I found a few shortcuts I think that I didn't know before to help me with long winded scripts so I don't have to hold down left/right ctrl +a is one I found helpful. [CODE]substring(string_to_search,string_to_find)=my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c[COLOR="Red"]=Vec()[/COLOR];for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);if(good,return(c)));0;eturn(c)));0;[/CODE] still not perfect in one sense and I'd want another vector to take from the end of the s2 found in s1 to the end to create a new s1 in one sense with the word/phrase replaced with something understandable. changed c=Vec() to c="" and works better still. |
my computer is weird and i can't find a virus weird anyways just insert a few things into your script for the vector and i can show you how to have fun with it lol.
|
[CODE]substring(string_to_search,string_to_find)=my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c="";for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);break));if(good,return(concat(c,"loser!"))));0;[/CODE]
this should be accurate CRG if you put: substring("Shut up 3.14159","3.14159") you should get a return of "Shut up loser!" :lol: something tells me someone will care lol. |
(Be nice!)
So your function (which should be called something like "replace") looks for the second string in the first. If it finds it, the function removes the found part and everything after it, replacing it and everything following with the fixed string "loser!" in this case (probably a third argument in a polished version). If the second string isn't found, it returns 0. |
[QUOTE=CRGreathouse;229067](Be nice!)
So your function (which should be called something like "replace") looks for the second string in the first. If it finds it, the function removes the found part and everything after it, replacing it and everything following with the fixed string "loser!" in this case (probably a third argument in a polished version). If the second string isn't found, it returns 0.[/QUOTE] or an error in the polished version to tell them none of this subgroup of the descriptions were found technically I want the final phrasing returned including the part after replacing then we can use substring to check for other substrings. in a for loop we could all a Vec of Vec that tell which Vec to check the descriptions in. yeah i know complicated lol. |
put this :
[CODE];for(x=i,#s1-1,d=concat(d,s1[x+1]));[/CODE] before the return and i think that's what I can do so far (still want it to check the rest of the string if i can do a simple replacement part I have a way with vector concatenation I think ,concat the index it finds it at into an array then use that array to do the replacements) Edit: declare it first near where c is declared if you go this way. |
I think there's an easier way:
1)find s2 in s1 record all until you found s1 in c (like I already have working) 2)have a replacement Vec of Vec with a value to replace S2 with 3)concat c and the replacement value onto a new variable. 4)clear C out; 5)Repeat 1..4 as needed until end of search for that string 6)change to a new Vec of Vec. 7)Repeat 1..6 until every search is done. 8)print out the result ? (maybe start finding a script to interpret what it's figured out.) |
[CODE]%113 = (string_to_search,string_to_find)->my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c="";d="";for(i=0,#s1-#s2,good=1;for(j=1,#s2,if(s2[j]!=s1[j+i],good=0;c=concat(c,s1[i+1]);break));if(good,d=concat(d,(concat(c,"loser!")))));return(d)
(18:32) gp > substring("hello Alex, Good bye Alex","Alex") ))));return(d) %114 = "hello loser!hello lex, Good bye loser!"[/CODE] best I can do for now maybe if i turn my steps to code I'll have more luck lol. |
| All times are UTC. The time now is 23:15. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.