aggixx Posted December 12, 2007 Author Share Posted December 12, 2007 hey, aggixx, can I get the funtion that saves all of the words into an array?I might be able to help if I know that function...*var here*.split ("*char where you want to divide it*") Link to comment Share on other sites More sharing options...
justsomeguy Posted December 12, 2007 Share Posted December 12, 2007 var word = str107.split(" ");http://devguru.com/technologies/javascript/10816.asp Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted December 12, 2007 Share Posted December 12, 2007 Thanks guys... Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted December 12, 2007 Share Posted December 12, 2007 I viewed the source of the cheeser page, and why does it say var str96 = str95.replace(/um/gi, "erm"); ? does it need that gi right there? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 12, 2007 Share Posted December 12, 2007 The g flag indicates that it should be a global replacement instead of replacing the first one it finds, and the i flag indicates that it is case-insensitive. Link to comment Share on other sites More sharing options...
aggixx Posted December 12, 2007 Author Share Posted December 12, 2007 This my complicated attempt at making it so that the punctuation is in the right place: alert("after replace: " + str107);var word = str107.split(" ");for (h = 0; h < word.length; h++) {str = new String(word[h]);var regexp1=new RegExp("(");if regexp.test(str)=true;{var hasleftpar = "("}else{var hasleftpar = ""}var regexp2=new RegExp(")");if regexp.test(str)=true;{var hasrightpar = ")"}else{var hasrightpar = ""}var regexp3=new RegExp("!");if regexp.test(str)=true;{var hasexppoint = "!"}else{var hasexppoint = ""}var regexp4=new RegExp("$");if regexp.test(str)=true;{var hasdollar = "$"}else{var hasdollar = ""}var regexp5=new RegExp("%");if regexp.test(str)=true;{var haspercent = "%"}else{var haspercent = ""}var regexp6=new RegExp("*");if regexp.test(str)=true;{var hasasterisk = "*"}else{var hasasterisk = ""}var regexp7=new RegExp("[");if regexp.test(str)=true;{var hasleftbrack = "["}else{var hasleftbrack = ""}var regexp8=new RegExp("]");if regexp.test(str)=true;{var hasrightbrack = "]"}else{var hasrightbrack = ""}var regexp9=new RegExp("{");if regexp.test(str)=true;{var hasleftcurvything = "{"}else{var hasleftcurvything = ""}var regexp10=new RegExp("}");if regexp.test(str)=true;{var hasrightcurvything = "}"}else{var hasrightcurvything = ""}var regexp11=new RegExp(";");if regexp.test(str)=true;{var hassemicolin = ";"}else{var hassemicolin = ""}var regexp12=new RegExp(":");if regexp.test(str)=true;{var hascolin = ":"}else{var hascolin = ""}var regexp13=new RegExp(",");if regexp.test(str)=true;{var hascomma = ","}else{var hascomma = ""}var regexp14=new RegExp(".");if regexp.test(str)=true;{var hasperiod = "."}else{var hasperiod = ""}var regexp15=new RegExp("?");if regexp.test(str)=true;{var hasquestion = "?"}else{var hasquestion = ""}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;}word[h] = hasleftpar+hasleftbrack+hasleftcurvything+str+hasexppoint+hasdollar+haspercent+hasasterisk+hassemicolin+hascolin+hascomma+hasperiod+hasquestion+hasrightpar+hasrightbrack+hasrightcurvything}document.conv.output.value = word.join(" ");} Doesn't work but I figured I would show my attempt so people don't think im lazy . Link to comment Share on other sites More sharing options...
aalbetski Posted December 12, 2007 Share Posted December 12, 2007 I'm curious if you tried my suggestion. It maintains punctuation and performs the task exactly as you had request with a minimal amount of code. var sText ="this is some text to change into piglatin\nThis has a new line, and all kinds? of punctuation. Give it a try!"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");}) Result:Hista Sia Omesa Extta Ota Hangeca Ntoia IglatinpaHista Asha aa Ewna Inela, Ndaa Llaa Indska? Foa Unctuationpa. Ivega Tia aa Ryta! Link to comment Share on other sites More sharing options...
justsomeguy Posted December 12, 2007 Share Posted December 12, 2007 Your example capitalizes every word. The way he made it sound was that the word should only be capitalized if it already contains a capital letter.With punctuation you need to work out some rules. Punctuation at the end would probably still want to be at the end, stuff at the beginning would probably want to remain at the beginning, but what about punctuation in the middle somewhere, like a hyphen or an apostrophe? Like the word "didn't", or "even-handed". Link to comment Share on other sites More sharing options...
aalbetski Posted December 12, 2007 Share Posted December 12, 2007 new result - only capitalizes the word if it was previously capped:idnda'ta ouya Antwa ota eba venea-andedha? Aleta foa wota itiesca: sia omesa ext ta ota hangeca ntoia iglatinpaHista asha aa ewna inela, ndaa llaa indska? foa unctuationpa. Ivega tia aa ryta!from this text:didn't you Want to be even-handed? Tale of two cities: is some text to change into piglatinThis has a new line, and all kinds? of punctuation. Give it a try! var sText ="didn't you want to be even-handed? Tale of two cities: is some text to change into piglatin\nThis has a new line, and all kinds? of punctuation. Give it a try!"var sText2 = ""var re = /(\b\w+\b)/gsText2 = sText.replace(re, function($1) { if ($1.match(/[A-Z]/g) == null) { return($1.substr(1,1) + $1.substr(2) + $1.substr(0,1).toLowerCase() + "a") } else { return($1.substr(1,1).toUpperCase() + $1.substr(2) + $1.substr(0,1).toLowerCase() + "a") } } ) Its easy to make adjustments once the rules are known. The punctuation in the middle may be an issue or may not be. If it is, we'll adjust our pattern match. Link to comment Share on other sites More sharing options...
aggixx Posted December 12, 2007 Author Share Posted December 12, 2007 Your example capitalizes every word. The way he made it sound was that the word should only be capitalized if it already contains a capital letter.With punctuation you need to work out some rules. Punctuation at the end would probably still want to be at the end, stuff at the beginning would probably want to remain at the beginning, but what about punctuation in the middle somewhere, like a hyphen or an apostrophe? Like the word "didn't", or "even-handed". new result - only capitalizes the word if it was previously capped:idnda'ta ouya Antwa ota eba venea-andedha? Aleta foa wota itiesca: sia omesa ext ta ota hangeca ntoia iglatinpaHista asha aa ewna inela, ndaa llaa indska? foa unctuationpa. Ivega tia aa ryta!from this text:didn't you Want to be even-handed? Tale of two cities: is some text to change into piglatinThis has a new line, and all kinds? of punctuation. Give it a try!var sText ="didn't you want to be even-handed? Tale of two cities: is some text to change into piglatin\nThis has a new line, and all kinds? of punctuation. Give it a try!"var sText2 = ""var re = /(\b\w+\b)/gsText2 = sText.replace(re, function($1) { if ($1.match(/[A-Z]/g) == null) { return($1.substr(1,1) + $1.substr(2) + $1.substr(0,1).toLowerCase() + "a") } else { return($1.substr(1,1).toUpperCase() + $1.substr(2) + $1.substr(0,1).toLowerCase() + "a") } } ) Its easy to make adjustments once the rules are known. The punctuation in the middle may be an issue or may not be. If it is, we'll adjust our pattern match. I'm not worrying about the middle punctuation, just beginning and end. Aalbetski, that doesn't work, gives me an error. If you want to see the result of that its at http://balder.prohosting.com/cheeser2/index2.htm Link to comment Share on other sites More sharing options...
justsomeguy Posted December 12, 2007 Share Posted December 12, 2007 The script online is trying to use a variable called return. You can't name something "return", that's a reserved word. Link to comment Share on other sites More sharing options...
aalbetski Posted December 12, 2007 Share Posted December 12, 2007 I modified some of your HTML and corrected a typo; Insert this section sText2 = sText.replace(re, function($1) { if ($1.match(/[A-Z]/g) == null) { return ($1.substr(1,1) + $1.substr(2) + $1.substr(0,1).toLowerCase() + "a") } else { return ($1.substr(1,1).toUpperCase() + $1.substr(2) + $1.substr(0,1).toLowerCase() + "a") } } ) document.conv.output.value = sText2 You can see the changes here: http://www.swband.org/Temp/chesse.htm Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.