Jump to content

Modified Pig Latin Script


aggixx

Recommended Posts

Im trying to make a pig latin script, but its probably not the type of pig latin you are used to, here are the rules:1. move only the first letter to end of word2. add the letter 'a'This is what I have so far, but I can't figure out how to make it move the letter first letter.

var text = str;	text = text.replace(/\b([abcdefghijklmnopqrstuvwxyz]+)([a-z]*)\b/gi, "$2$1a");	document.conv.output.value = text;

Thanks in advance to anyone helps.

Link to comment
Share on other sites

  • 3 weeks later...
Umm... what about
$text = text.replace(/([a-z]*?)([a-z])/gi, "$2$1a");

sorry, that doesn't work...I have finally figured it out though, but now I need to make it so that if there is a capital in the word, it uncapitalizes it and recapitalizes the first letter. Here is what I have:
  document.conv.output.value = str107  var word = document.conv.output.value.split (" ")   outp = ""  for (i = 0; i < word.length; i++) { 	thisword = word [i]	outp = outp + thisword.substring (1, thisword.length) + thisword.substring(0,1) + "a "  }   document.conv.output.value = outp   var capitalizer = document.conv.output.value.split (" ")  outp = ""  for (i = 0; i < capitalizer.length; i++} {	thisword = capitalizer [i]	var regexp1 = new RegExp([ABCDEFGHIJKLMNOPQRSTUVWXYZ])	if regexp1.test(thisword) = "true"	{	outp = capsLc(thisword)	}	else	{	outp = thisword	}  document.conv.output.value = outp function capsLc(thisword){if (navigator.appVersion.substring(0,1)=="2"){navOld(thisword);}else navNew(thisword);}function navOld(thisword){txt=thisword+" ";txt=txt.toLowerCase();txtl="";while ((txt.length>0)&&(txt.indexOf(" ")>-1)){pos=txt.indexOf(" ");wrd=txt.substring(0,pos);cmp=" "+wrd+" ";if (tst.indexOf(cmp)<0){ltr=wrd.substring(0,1);ltr=ltr.toUpperCase();wrd=ltr+wrd.substring(1,wrd.length);}txtl+=wrd+" ";txt=txt.substring((pos+1),txt.length);}ltr=txtl.substring(0,1);ltr=ltr.toUpperCase();txtl=ltr+txtl.substring(1,txtl.length-1);document.isn.caps.value=txtl;}function navNew(thisword){txt=thisword+" ";txt=txt.toLowerCase();txtl="";punc=",.?!:;)'";punc+='"'; while ((txt.length>0)&&(txt.indexOf(" ")>-1)){pos=txt.indexOf(" ");wrd=txt.substring(0,pos);wrdpre="";if (punc.indexOf(wrd.substring(0,1))>-1){wrdpre=wrd.substring(0,1);wrd=wrd.substring(1,wrd.length);}cmp=" "+wrd+" ";for (var i=0;i<9;i++){p=wrd.indexOf(punc.substring(i,i+1));if (p==wrd.length-1){cmp=" "+wrd.substring(0,wrd.length-1)+" ";i=9;   }}if (cmp.indexOf(cmp)<0){ltr=wrd.substring(0,1);ltr=ltr.toUpperCase();wrd=ltr+wrd.substring(1,wrd.length);}txtl+=wrdpre+wrd+" ";txt=txt.substring((pos+1),txt.length);}ltr=txtl.substring(0,1);ltr=ltr.toUpperCase();txtl=ltr+txtl.substring(1,txtl.length-1);document.isn.caps.value=txtl;}

Link to comment
Share on other sites

Geez, is all that code to move the first letter to the end, add an a, and capitalize the first letter?

// str is the string to convertstr = "Testing";var has_cap = false;for (i = 0; i < str.length; i++)  if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91)  {	has_cap = true;	break;  }car = str.substr(0,1);cdr = str.substr(1);str = cdr + car + "a";if (has_cap){  str = str.toLowerCase();  str = str.substr(0,1).toUpperCase() + str.substr(1);}alert(str);

Link to comment
Share on other sites

Geez, is all that code to move the first letter to the end, add an a, and capitalize the first letter?
// str is the string to convertstr = "Testing";var has_cap = false;for (i = 0; i < str.length; i++)  if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91)  {	has_cap = true;	break;  }car = str.substr(0,1);cdr = str.substr(1);str = cdr + car + "a";if (has_cap){  str = str.toLowerCase();  str = str.substr(0,1).toUpperCase() + str.substr(1);}alert(str);

that doesnt exactly work for me...
Link to comment
Share on other sites

Works for me... what is wrong?
Nvm, it works, I just had to do a large amount of editing to make it fit the script. Ill tell you if there is any problems. edit: since this only works for one word as far as I can tell im going to have to fix that, ill repost the finished script when im done. Im going to need some help with fitting this into the script:basically the guidelines are that this script supports multiple words, so I use the function split, which takes the string and makes an array. This way it runs each word through the script then reassembles it. Please help fix the script below...
  var word = str107.split (" ")   outp = ""   for (i = 0; i < word.length; i++) { 	str107 = word [i]	 	 // str is the string to convert	 str = str107;	 var has_cap = false;	 for (i = 0; i < str.length; i++)	   if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91)	   {		 has_cap = true;		 break;	   }	 car = str.substr(0,1);	 cdr = str.substr(1);	 str = cdr + car + "a";	 if (has_cap)	 {	   str = str.toLowerCase();	   str = str.substr(0,1).toUpperCase() + str.substr(1);	 }	} 	document.conv.output.value = str   }

Link to comment
Share on other sites

Try this. It just edits the words inside the word array then joins them back together.

  var word = str107.split(" ");  for (i = 0; i < word.length; i++) {	 str = word[i];	 has_cap = false;	 for (i = 0; i < str.length; i++)	   if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91)	   {		 has_cap = true;		 break;	   }	 car = str.substr(0,1);	 cdr = str.substr(1);	 str = cdr + car + "a";	 if (has_cap)	 {	   str = str.toLowerCase();	   str = str.substr(0,1).toUpperCase() + str.substr(1);	 }	 word[i] = str;	}	document.conv.output.value = word.join(" ");  }

Link to comment
Share on other sites

Try this. It just edits the words inside the word array then joins them back together.
it still doesn't work for me :):) .not sure what the problem is, input variable and output variable seem to be right, but when I press a button on the script nothing happens and the little error symbol shows up in the corner of the browser. Would you like me to upload the script to my host?
Link to comment
Share on other sites

Just had to throw my attempt in, try this.

var sText ="this is some text to change into piglatin"var sText2 = ""var re = /(\b\w+\b)/gsText2 = sText.replace(re, function($1) { return($1.substr(1,1).toUpperCase() + $1.substr(2) + $1.substr(0,1).toLowerCase() + "a");})

Link to comment
Share on other sites

That one doesn't do the check if there are capital letters, it just capitalizes everything.Also, IE is a lousy Javascript debugger. Firefox and Opera (and Safari, and Netscape) all have better Javascript debugging then IE's pseudo-random numbers. If you want to post it online I'll take a look at it with Opera.

Link to comment
Share on other sites

That one doesn't do the check if there are capital letters, it just capitalizes everything.Also, IE is a lousy Javascript debugger. Firefox and Opera (and Safari, and Netscape) all have better Javascript debugging then IE's pseudo-random numbers. If you want to post it online I'll take a look at it with Opera.
Just so you know, Im making a code that has two parts one of which is piglatin, the function we are looking at is named convert(), and runs when the 'Convert to Cheeser Code' Button is hit. (Dont tell me the name is bad, i didnt come up with it :) )http://cheeser.vzz.net
Link to comment
Share on other sites

Here's the output from Opera:CSS - http://cheeser.vzz.net/HTML style attributeDeclaration syntax errorLine 1: visibility: hidden; filter:progid:DXImageTransform.Microsoft.alpha(opacity=80); --------------------------------------------------------------------------------^ JavaScript - http://cheeser.vzz.net/Inline script compilationSyntax error while loading: line 137 of inline script at http://cheeser.vzz.net/ :Junk at the end of input}-^JavaScript - http://cheeser.vzz.net/Event thread: clickError:name: ReferenceErrormessage: Undefined variable: convertBacktrace: ...The error on line 137 is referencing a curly bracket that shouldn't be there.

word = str; } document.conv.output.value = word.join(" "); }}
Link to comment
Share on other sites

Here's the output from Opera:CSS - http://cheeser.vzz.net/HTML style attributeDeclaration syntax errorLine 1:visibility: hidden; filter:progid:DXImageTransform.Microsoft.alpha(opacity=80);--------------------------------------------------------------------------------^JavaScript - http://cheeser.vzz.net/Inline script compilationSyntax error while loading: line 137 of inline script at http://cheeser.vzz.net/ :Junk at the end of input}-^JavaScript - http://cheeser.vzz.net/Event thread: clickError:name: ReferenceErrormessage: Undefined variable: convertBacktrace:...The error on line 137 is referencing a curly bracket that shouldn't be there.
Still another error, This time it outputs the first step, and stops, and doesn't do the pig latin. Its saying length isn't a valid object...
Link to comment
Share on other sites

Well it did fix that error, now there's another one.JavaScript - http://cheeser.vzz.net/Event thread: clickError:name: TypeErrormessage: Statement on line 134: Type mismatch (usually non-object value supplied where object required)Backtrace: Line 134 of inline#1 script in http://cheeser.vzz.net/: In function convert document.conv.output.value = word.join(" "); ...The word variable isn't an array. Instead of this line:var word = document.conv.output.value.split;It needs to be this:var word = document.conv.output.value.split(" ");It would be better to just make it this:var word = str107.split(" ");

Link to comment
Share on other sites

Well it did fix that error, now there's another one.JavaScript - http://cheeser.vzz.net/Event thread: clickError:name: TypeErrormessage: Statement on line 134: Type mismatch (usually non-object value supplied where object required)Backtrace:Line 134 of inline#1 script in http://cheeser.vzz.net/: In function convertdocument.conv.output.value = word.join(" ");...The word variable isn't an array. Instead of this line:var word = document.conv.output.value.split;It needs to be this:var word = document.conv.output.value.split(" ");It would be better to just make it this:var word = str107.split(" ");
No errors this time but it has a weird output, looks like it doesn't do the piglatin for anything except for the first word. Seems only to support three words, and when there is a third word it adds the correct version of the second word to the end.
Link to comment
Share on other sites

Good lord, your site has the worst advertising on it, I had to block all kinds of content to get it to stop. You need a different host, if that's the way hostultra operates then find another one. If they're willing to sabotage your site like that (sometimes the ads straight up redirected me off your site, not to mention sending out a rapid fire string of requests giving whatever personal information they can get to anyone) then they're probably willing to screw with you in other ways also. Vote with your feet and find another host, if I didn't already configure my browser to stop that crap I would tell you I'm not going to go to that site if it's on hostultra.Add some alerts to the code to figure out what's going on. After you do your legion of regular expression replacements alert the result of that to make sure it's what you expect, then alert each word in the array that it loops through to figure out where it's going wrong.

var str107 = str106.replace(/uz/gi, "erz");  alert("after replace: " + str107);  var word = str107.split(" ");  for (i = 0; i < word.length; i++) {	str = new String(word[i]);		alert("before: " + str);	has_cap = false;	for (i = 0; i < str.length; i++)	  if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91)	  {		has_cap = true;		break;	  }	car = str.substr(0,1);	cdr = str.substr(1);	str = cdr + car + "a";	if (has_cap)	{	  str = str.toLowerCase();	  str = str.substr(0,1).toUpperCase() + str.substr(1);	}	alert("after: " + str);	word[i] = str;  }  document.conv.output.value = word.join(" ");

Link to comment
Share on other sites

Good lord, your site has the worst advertising on it, I had to block all kinds of content to get it to stop. You need a different host, if that's the way hostultra operates then find another one. If they're willing to sabotage your site like that (sometimes the ads straight up redirected me off your site, not to mention sending out a rapid fire string of requests giving whatever personal information they can get to anyone) then they're probably willing to screw with you in other ways also. Vote with your feet and find another host, if I didn't already configure my browser to stop that crap I would tell you I'm not going to go to that site if it's on hostultra.Add some alerts to the code to figure out what's going on. After you do your legion of regular expression replacements alert the result of that to make sure it's what you expect, then alert each word in the array that it loops through to figure out where it's going wrong.
var str107 = str106.replace(/uz/gi, "erz");  alert("after replace: " + str107);  var word = str107.split(" ");  for (i = 0; i < word.length; i++) {	str = new String(word[i]);		alert("before: " + str);	has_cap = false;	for (i = 0; i < str.length; i++)	  if (str.charCodeAt(i) > 64 && str.charCodeAt(i) < 91)	  {		has_cap = true;		break;	  }	car = str.substr(0,1);	cdr = str.substr(1);	str = cdr + car + "a";	if (has_cap)	{	  str = str.toLowerCase();	  str = str.substr(0,1).toUpperCase() + str.substr(1);	}	alert("after: " + str);	word[i] = str;  }  document.conv.output.value = word.join(" ");

Try it now...http://balder.prohosting.com/cheeser2
Link to comment
Share on other sites

Oops. The nested for loop is using the same iterator as the outer for loop. I changed the nested one to use j instead of i.

		for (i = 0; i < word.length; i++) {		  str = new String(word[i]);  		  has_cap = false;		  for (j = 0; j < str.length; j++)			if (str.charCodeAt(j) > 64 && str.charCodeAt(j) < 91)			{			  has_cap = true;			  break;			}		  car = str.substr(0,1);		  cdr = str.substr(1);		  str = cdr + car + "a";		  if (has_cap)		  {			str = str.toLowerCase();			str = str.substr(0,1).toUpperCase() + str.substr(1);		  }		  word[i] = str;		}

Link to comment
Share on other sites

Oops. The nested for loop is using the same iterator as the outer for loop. I changed the nested one to use j instead of i.
		for (i = 0; i < word.length; i++) {<BR>		  str = new String(word[i]);<BR>  <BR>		  has_cap = false;<BR>		  for (j = 0; j < str.length; j++)<BR>			if (str.charCodeAt(j) > 64 && str.charCodeAt(j) < 91)<BR>			{<BR>			  has_cap = true;<BR>			  break;<BR>			}<BR><BR>		  car = str.substr(0,1);<BR>		  cdr = str.substr(1);<BR>		  str = cdr + car + "a";<BR><BR>		  if (has_cap)<BR>		  {<BR>			str = str.toLowerCase();<BR>			str = str.substr(0,1).toUpperCase() + str.substr(1);<BR>		  }<BR>		  word[i] = str;<BR>		}

Yay its working!!! Thanks. If its not too much of a trouble could you help me add a thing for punctuation<--,!.;?:-->?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...