![]() |
|
|
#1354 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
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.
|
|
|
|
|
|
#1355 |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
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.
Last fiddled with by science_man_88 on 2010-09-08 at 17:15 |
|
|
|
|
|
#1356 |
|
Aug 2006
3×1,993 Posts |
I can't understand you, but I'm glad my script seems to have been useful, either as inspiration or as a tool.
|
|
|
|
|
|
#1357 | |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
Quote:
Code:
substring(string_to_search,string_to_find)=my(s1=Vec(string_to_search),s2=Vec(string_to_find),good);c=Vec();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; changed c=Vec() to c="" and works better still. Last fiddled with by science_man_88 on 2010-09-08 at 17:31 |
|
|
|
|
|
|
#1358 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
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.
|
|
|
|
|
|
#1359 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
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; substring("Shut up 3.14159","3.14159") you should get a return of "Shut up loser!" something tells me someone will care lol.
|
|
|
|
|
|
#1360 |
|
Aug 2006
3·1,993 Posts |
(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. |
|
|
|
|
|
#1361 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
|
|
|
|
|
|
|
#1362 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
put this :
Code:
;for(x=i,#s1-1,d=concat(d,s1[x+1])); Edit: declare it first near where c is declared if you go this way. Last fiddled with by science_man_88 on 2010-09-08 at 20:04 |
|
|
|
|
|
#1363 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
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.) |
|
|
|
|
|
#1364 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
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!"
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why do I sometimes see all the <> formatting commands when I quote or edit? | cheesehead | Forum Feedback | 3 | 2013-05-25 12:56 |
| Passing commands to PARI on Windows | James Heinrich | Software | 2 | 2012-05-13 19:19 |
| Ubiquity commands | Mini-Geek | Aliquot Sequences | 1 | 2009-09-22 19:33 |
| 64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |
| Are these commands correct? | jasong | Linux | 2 | 2007-10-18 23:40 |