Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34345 > unrolled thread
| Started by | jonas.thornvall@gmail.com |
|---|---|
| First post | 2017-11-14 02:34 -0800 |
| Last post | 2017-11-14 04:47 -0800 |
| Articles | 10 — 4 participants |
Back to article view | Back to comp.lang.javascript
Script reload on leaving? jonas.thornvall@gmail.com - 2017-11-14 02:34 -0800
Re: Script reload on leaving? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-14 02:44 -0800
Re: Script reload on leaving? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-14 04:45 -0800
Re: Script reload on leaving? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-14 04:52 -0800
Re: Script reload on leaving? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-14 04:53 -0800
Re: Script reload on leaving? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-14 05:33 -0800
Re: Script reload on leaving? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-14 12:04 -0800
Re: Script reload on leaving? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2017-11-14 16:52 -0800
Re: Script reload on leaving? Tim Streater <timstreater@greenbee.net> - 2017-11-14 14:43 +0000
Re: Script reload on leaving? Julio Di Egidio <julio@diegidio.name> - 2017-11-14 04:47 -0800
| From | jonas.thornvall@gmail.com |
|---|---|
| Date | 2017-11-14 02:34 -0800 |
| Subject | Script reload on leaving? |
| Message-ID | <f1f81714-4b4f-4e5d-b989-75a3c312a538@googlegroups.com> |
This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
<!DOCTYPE html>
<html>
<head>
<meta http-Equiv="content-type" content="text/html; charset=UTF-8">
</head>
<script>
function createStruct() {
newword=true;
beeninside=false;
oldlevel=-1;
deeplevel = -1;
wordlevel= -1;
inserted = false;
leftstruct = "[";
rightstruct = "]";
endstruct = "*";
separator = " ";
subseparator = "";
newString= "";
stringPrevMem = "";
stringMem = "";
posStructString="";
//Get values to read in
encodedString = document.getElementById("encodedText").value;
mystr = document.getElementById("inputTextToSave").value;
//Split string into words to read in
strArr = mystr.split(separator);
//Search words
for (var x = 0; x < strArr.length; x++) {
newString=strArr[x];
stringInserted=false;
searchItem(newString);
}
printArray();
alert("closing script");
}
function searchItem(newString) {
oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
while (z < encodedString.length && stringInserted==false) {
if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
// alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
// alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "*") {
//decoded word in memory
newword=true; beeninside=false;
// alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
} else {
stringMem += encodedString.charAt(z);
newSubString=newString.substring(0,stringMem.length);
if (newSubString==stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
}
else if (newSubString>stringMem && newword==true && beeninside==false) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
newword=false;beeninside=true;
stringPrevMem = stringMem;
}
else if (newSubString<stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
checkWhatTOInsert();
}
}
z++;
}
}
function checkWhatTOInsert(){
putString="";
if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
else {insertString = newString.substring(newSubString.length, newString.length);}
insertChar = insertString.split('');
for (var m=0;m<insertChar.length;m++){
putString+="["+insertChar[m];
}
putString+="*";
for (var m=0;m<insertChar.length;m++){
putString+="]";
}
encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
document.getElementById("encodedText").value=encodedString;
stringInserted=true;
// alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
}
function insertSubstring(str, index, value) {
return str.substr(0, index) + value + str.substr(index);
}
function printArray() {
encodedString = document.getElementById("encodedText").value;
stringMem="";oldlevel=-1;deeplevel=-1;
for (var z = 0; z < encodedString.length; z++) {
if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
} else if (encodedString.charAt(z) == "*") {
document.getElementById("decodedText").value+=stringMem+"\n";
} else {
stringMem += encodedString.charAt(z);
}
}
}
</script>
<body onload="printArray();">
<form onSubmit="createStruct();">
<input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
</form>
<br>
<Font size="4">DEBUG</Font><br>
<textarea id="debug" cols="80" rows="3"></textarea><br>
<br>
<Font size="4">INSERT IN STRUCTURE</Font><br>
<textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
<br>
<Font size="4">STRUCTURE</Font><br>
<textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
<br>
<Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
<textarea id="decodedText" cols="80" rows="12"></textarea><br>
</body>
</html>
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-14 02:44 -0800 |
| Message-ID | <2afa0a21-b5fd-4e7c-8774-d4060b4c964d@googlegroups.com> |
| In reply to | #34345 |
Den tisdag 14 november 2017 kl. 11:34:28 UTC+1 skrev Jonas Thörnvall:
> This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
>
> It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> </head>
> <script>
> function createStruct() {
> newword=true;
> beeninside=false;
> oldlevel=-1;
> deeplevel = -1;
> wordlevel= -1;
> inserted = false;
> leftstruct = "[";
> rightstruct = "]";
> endstruct = "*";
> separator = " ";
> subseparator = "";
> newString= "";
> stringPrevMem = "";
> stringMem = "";
> posStructString="";
> //Get values to read in
> encodedString = document.getElementById("encodedText").value;
> mystr = document.getElementById("inputTextToSave").value;
> //Split string into words to read in
> strArr = mystr.split(separator);
> //Search words
> for (var x = 0; x < strArr.length; x++) {
>
> newString=strArr[x];
> stringInserted=false;
> searchItem(newString);
> }
> printArray();
> alert("closing script");
> }
>
> function searchItem(newString) {
> oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> while (z < encodedString.length && stringInserted==false) {
>
> if (encodedString.charAt(z) == "[") {
> oldlevel=deeplevel;
> deeplevel++;
> // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> } else if (encodedString.charAt(z) == "]") {
> oldlevel=deeplevel;
> deeplevel--;
> stringMem = stringMem.slice(0, -1);
> // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> } else if (encodedString.charAt(z) == "*") {
> //decoded word in memory
> newword=true; beeninside=false;
> // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> } else {
> stringMem += encodedString.charAt(z);
> newSubString=newString.substring(0,stringMem.length);
> if (newSubString==stringMem) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> }
> else if (newSubString>stringMem && newword==true && beeninside==false) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> newword=false;beeninside=true;
> stringPrevMem = stringMem;
> }
> else if (newSubString<stringMem) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> checkWhatTOInsert();
> }
> }
> z++;
> }
> }
>
>
> function checkWhatTOInsert(){
> putString="";
> if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> else {insertString = newString.substring(newSubString.length, newString.length);}
>
> insertChar = insertString.split('');
> for (var m=0;m<insertChar.length;m++){
> putString+="["+insertChar[m];
> }
> putString+="*";
> for (var m=0;m<insertChar.length;m++){
> putString+="]";
> }
> encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> document.getElementById("encodedText").value=encodedString;
> stringInserted=true;
> // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> }
>
> function insertSubstring(str, index, value) {
> return str.substr(0, index) + value + str.substr(index);
> }
>
> function printArray() {
>
> encodedString = document.getElementById("encodedText").value;
> stringMem="";oldlevel=-1;deeplevel=-1;
> for (var z = 0; z < encodedString.length; z++) {
> if (encodedString.charAt(z) == "[") {
> oldlevel=deeplevel;
> deeplevel++;
> } else if (encodedString.charAt(z) == "]") {
> oldlevel=deeplevel;
> deeplevel--;
> stringMem = stringMem.slice(0, -1);
> } else if (encodedString.charAt(z) == "*") {
> document.getElementById("decodedText").value+=stringMem+"\n";
>
> } else {
> stringMem += encodedString.charAt(z);
> }
> }
> }
> </script>
> <body onload="printArray();">
> <form onSubmit="createStruct();">
> <input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
> </form>
> <br>
> <Font size="4">DEBUG</Font><br>
> <textarea id="debug" cols="80" rows="3"></textarea><br>
> <br>
> <Font size="4">INSERT IN STRUCTURE</Font><br>
> <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> <br>
> <Font size="4">STRUCTURE</Font><br>
> <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> <br>
> <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> </body>
> </html>
I can't see how these could do anything wrong, writing to textarea what am i missing?
document.getElementById("encodedText").value=encodedString;
document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-14 04:45 -0800 |
| Message-ID | <ba1c66de-fc1d-42db-81f7-2e8a8d24a91d@googlegroups.com> |
| In reply to | #34346 |
Den tisdag 14 november 2017 kl. 11:44:36 UTC+1 skrev Jonas Thörnvall:
> Den tisdag 14 november 2017 kl. 11:34:28 UTC+1 skrev Jonas Thörnvall:
> > This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
> >
> > It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
> >
> > <!DOCTYPE html>
> > <html>
> > <head>
> > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > </head>
> > <script>
> > function createStruct() {
> > newword=true;
> > beeninside=false;
> > oldlevel=-1;
> > deeplevel = -1;
> > wordlevel= -1;
> > inserted = false;
> > leftstruct = "[";
> > rightstruct = "]";
> > endstruct = "*";
> > separator = " ";
> > subseparator = "";
> > newString= "";
> > stringPrevMem = "";
> > stringMem = "";
> > posStructString="";
> > //Get values to read in
> > encodedString = document.getElementById("encodedText").value;
> > mystr = document.getElementById("inputTextToSave").value;
> > //Split string into words to read in
> > strArr = mystr.split(separator);
> > //Search words
> > for (var x = 0; x < strArr.length; x++) {
> >
> > newString=strArr[x];
> > stringInserted=false;
> > searchItem(newString);
> > }
> > printArray();
> > alert("closing script");
> > }
> >
> > function searchItem(newString) {
> > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > while (z < encodedString.length && stringInserted==false) {
> >
> > if (encodedString.charAt(z) == "[") {
> > oldlevel=deeplevel;
> > deeplevel++;
> > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > } else if (encodedString.charAt(z) == "]") {
> > oldlevel=deeplevel;
> > deeplevel--;
> > stringMem = stringMem.slice(0, -1);
> > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > } else if (encodedString.charAt(z) == "*") {
> > //decoded word in memory
> > newword=true; beeninside=false;
> > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > } else {
> > stringMem += encodedString.charAt(z);
> > newSubString=newString.substring(0,stringMem.length);
> > if (newSubString==stringMem) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > }
> > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > newword=false;beeninside=true;
> > stringPrevMem = stringMem;
> > }
> > else if (newSubString<stringMem) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > checkWhatTOInsert();
> > }
> > }
> > z++;
> > }
> > }
> >
> >
> > function checkWhatTOInsert(){
> > putString="";
> > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > else {insertString = newString.substring(newSubString.length, newString.length);}
> >
> > insertChar = insertString.split('');
> > for (var m=0;m<insertChar.length;m++){
> > putString+="["+insertChar[m];
> > }
> > putString+="*";
> > for (var m=0;m<insertChar.length;m++){
> > putString+="]";
> > }
> > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > document.getElementById("encodedText").value=encodedString;
> > stringInserted=true;
> > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > }
> >
> > function insertSubstring(str, index, value) {
> > return str.substr(0, index) + value + str.substr(index);
> > }
> >
> > function printArray() {
> >
> > encodedString = document.getElementById("encodedText").value;
> > stringMem="";oldlevel=-1;deeplevel=-1;
> > for (var z = 0; z < encodedString.length; z++) {
> > if (encodedString.charAt(z) == "[") {
> > oldlevel=deeplevel;
> > deeplevel++;
> > } else if (encodedString.charAt(z) == "]") {
> > oldlevel=deeplevel;
> > deeplevel--;
> > stringMem = stringMem.slice(0, -1);
> > } else if (encodedString.charAt(z) == "*") {
> > document.getElementById("decodedText").value+=stringMem+"\n";
> >
> > } else {
> > stringMem += encodedString.charAt(z);
> > }
> > }
> > }
> > </script>
> > <body onload="printArray();">
> > <form onSubmit="createStruct();">
> > <input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
> > </form>
> > <br>
> > <Font size="4">DEBUG</Font><br>
> > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > <br>
> > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > <br>
> > <Font size="4">STRUCTURE</Font><br>
> > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > <br>
> > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > </body>
> > </html>
>
> I can't see how these could do anything wrong, writing to textarea what am i missing?
>
> document.getElementById("encodedText").value=encodedString;
> document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
Changed to button problem fixed.
<!DOCTYPE html>
<html>
<head>
<meta http-Equiv="content-type" content="text/html; charset=UTF-8">
</head>
<script>
function createStruct() {
newword=true;
beeninside=false;
oldlevel=-1;
deeplevel = -1;
wordlevel= -1;
inserted = false;
leftstruct = "[";
rightstruct = "]";
endstruct = "*";
separator = " ";
subseparator = "";
newString= "";
stringPrevMem = "";
stringMem = "";
posStructString="";
//Get values to read in
encodedString = document.getElementById("encodedText").value;
mystr = document.getElementById("inputTextToSave").value;
//Split string into words to read in
strArr = mystr.split(separator);
//Search words
for (var x = 0; x < strArr.length; x++) {
newString=strArr[x];
stringInserted=false;
searchItem(newString);
printArray();
}
alert("closing script");
}
function searchItem(newString) {
oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
while (z < encodedString.length && stringInserted==false) {
if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
// alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
// alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "*") {
//decoded word in memory
newword=true; beeninside=false;
// alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
} else {
stringMem += encodedString.charAt(z);
newSubString=newString.substring(0,stringMem.length);
if (newSubString==stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
}
else if (newSubString>stringMem && newword==true && beeninside==false) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
newword=false;beeninside=true;
stringPrevMem = stringMem;
}
else if (newSubString<stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
checkWhatTOInsert();
}
}
z++;
}
}
function checkWhatTOInsert(){
putString="";
if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
else {insertString = newString.substring(newSubString.length, newString.length);}
insertChar = insertString.split('');
for (var m=0;m<insertChar.length;m++){
putString+="["+insertChar[m];
}
putString+="*";
for (var m=0;m<insertChar.length;m++){
putString+="]";
}
encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
document.getElementById("encodedText").value=encodedString;
stringInserted=true;
// alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
}
function insertSubstring(str, index, value) {
return str.substr(0, index) + value + str.substr(index);
}
function printArray() {
encodedString = document.getElementById("encodedText").value;
stringMem="";oldlevel=-1;deeplevel=-1;
for (var z = 0; z < encodedString.length; z++) {
if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
} else if (encodedString.charAt(z) == "*") {
document.getElementById("decodedText").value+=stringMem+"\n";
} else {
stringMem += encodedString.charAt(z);
}
}
}
</script>
<body onload="printArray();">
<button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
<br>
<Font size="4">DEBUG</Font><br>
<textarea id="debug" cols="80" rows="3"></textarea><br>
<br>
<Font size="4">INSERT IN STRUCTURE</Font><br>
<textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
<br>
<Font size="4">STRUCTURE</Font><br>
<textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
<br>
<Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
<textarea id="decodedText" cols="80" rows="12"></textarea><br>
</body>
</html>
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-14 04:52 -0800 |
| Message-ID | <f9b44d20-26b5-42a8-8d00-287ed06d81b2@googlegroups.com> |
| In reply to | #34348 |
Den tisdag 14 november 2017 kl. 13:45:45 UTC+1 skrev Jonas Thörnvall:
> Den tisdag 14 november 2017 kl. 11:44:36 UTC+1 skrev Jonas Thörnvall:
> > Den tisdag 14 november 2017 kl. 11:34:28 UTC+1 skrev Jonas Thörnvall:
> > > This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
> > >
> > > It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
> > >
> > > <!DOCTYPE html>
> > > <html>
> > > <head>
> > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > </head>
> > > <script>
> > > function createStruct() {
> > > newword=true;
> > > beeninside=false;
> > > oldlevel=-1;
> > > deeplevel = -1;
> > > wordlevel= -1;
> > > inserted = false;
> > > leftstruct = "[";
> > > rightstruct = "]";
> > > endstruct = "*";
> > > separator = " ";
> > > subseparator = "";
> > > newString= "";
> > > stringPrevMem = "";
> > > stringMem = "";
> > > posStructString="";
> > > //Get values to read in
> > > encodedString = document.getElementById("encodedText").value;
> > > mystr = document.getElementById("inputTextToSave").value;
> > > //Split string into words to read in
> > > strArr = mystr.split(separator);
> > > //Search words
> > > for (var x = 0; x < strArr.length; x++) {
> > >
> > > newString=strArr[x];
> > > stringInserted=false;
> > > searchItem(newString);
> > > }
> > > printArray();
> > > alert("closing script");
> > > }
> > >
> > > function searchItem(newString) {
> > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > while (z < encodedString.length && stringInserted==false) {
> > >
> > > if (encodedString.charAt(z) == "[") {
> > > oldlevel=deeplevel;
> > > deeplevel++;
> > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > } else if (encodedString.charAt(z) == "]") {
> > > oldlevel=deeplevel;
> > > deeplevel--;
> > > stringMem = stringMem.slice(0, -1);
> > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > } else if (encodedString.charAt(z) == "*") {
> > > //decoded word in memory
> > > newword=true; beeninside=false;
> > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > newSubString=newString.substring(0,stringMem.length);
> > > if (newSubString==stringMem) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > }
> > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > newword=false;beeninside=true;
> > > stringPrevMem = stringMem;
> > > }
> > > else if (newSubString<stringMem) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > checkWhatTOInsert();
> > > }
> > > }
> > > z++;
> > > }
> > > }
> > >
> > >
> > > function checkWhatTOInsert(){
> > > putString="";
> > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > >
> > > insertChar = insertString.split('');
> > > for (var m=0;m<insertChar.length;m++){
> > > putString+="["+insertChar[m];
> > > }
> > > putString+="*";
> > > for (var m=0;m<insertChar.length;m++){
> > > putString+="]";
> > > }
> > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > document.getElementById("encodedText").value=encodedString;
> > > stringInserted=true;
> > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > }
> > >
> > > function insertSubstring(str, index, value) {
> > > return str.substr(0, index) + value + str.substr(index);
> > > }
> > >
> > > function printArray() {
> > >
> > > encodedString = document.getElementById("encodedText").value;
> > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > for (var z = 0; z < encodedString.length; z++) {
> > > if (encodedString.charAt(z) == "[") {
> > > oldlevel=deeplevel;
> > > deeplevel++;
> > > } else if (encodedString.charAt(z) == "]") {
> > > oldlevel=deeplevel;
> > > deeplevel--;
> > > stringMem = stringMem.slice(0, -1);
> > > } else if (encodedString.charAt(z) == "*") {
> > > document.getElementById("decodedText").value+=stringMem+"\n";
> > >
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > }
> > > }
> > > }
> > > </script>
> > > <body onload="printArray();">
> > > <form onSubmit="createStruct();">
> > > <input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
> > > </form>
> > > <br>
> > > <Font size="4">DEBUG</Font><br>
> > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > <br>
> > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > <br>
> > > <Font size="4">STRUCTURE</Font><br>
> > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > <br>
> > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > </body>
> > > </html>
> >
> > I can't see how these could do anything wrong, writing to textarea what am i missing?
> >
> > document.getElementById("encodedText").value=encodedString;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
>
> Changed to button problem fixed.
>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> </head>
> <script>
> function createStruct() {
> newword=true;
> beeninside=false;
> oldlevel=-1;
> deeplevel = -1;
> wordlevel= -1;
> inserted = false;
> leftstruct = "[";
> rightstruct = "]";
> endstruct = "*";
> separator = " ";
> subseparator = "";
> newString= "";
> stringPrevMem = "";
> stringMem = "";
> posStructString="";
> //Get values to read in
> encodedString = document.getElementById("encodedText").value;
> mystr = document.getElementById("inputTextToSave").value;
> //Split string into words to read in
> strArr = mystr.split(separator);
> //Search words
> for (var x = 0; x < strArr.length; x++) {
> newString=strArr[x];
> stringInserted=false;
> searchItem(newString);
> printArray();
> }
>
> alert("closing script");
> }
>
> function searchItem(newString) {
> oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> while (z < encodedString.length && stringInserted==false) {
>
> if (encodedString.charAt(z) == "[") {
> oldlevel=deeplevel;
> deeplevel++;
> // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> } else if (encodedString.charAt(z) == "]") {
> oldlevel=deeplevel;
> deeplevel--;
> stringMem = stringMem.slice(0, -1);
> // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> } else if (encodedString.charAt(z) == "*") {
> //decoded word in memory
> newword=true; beeninside=false;
> // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> } else {
> stringMem += encodedString.charAt(z);
> newSubString=newString.substring(0,stringMem.length);
> if (newSubString==stringMem) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> }
> else if (newSubString>stringMem && newword==true && beeninside==false) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> newword=false;beeninside=true;
> stringPrevMem = stringMem;
> }
> else if (newSubString<stringMem) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> checkWhatTOInsert();
> }
> }
> z++;
> }
> }
>
>
> function checkWhatTOInsert(){
> putString="";
> if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> else {insertString = newString.substring(newSubString.length, newString.length);}
>
> insertChar = insertString.split('');
> for (var m=0;m<insertChar.length;m++){
> putString+="["+insertChar[m];
> }
> putString+="*";
> for (var m=0;m<insertChar.length;m++){
> putString+="]";
> }
> encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> document.getElementById("encodedText").value=encodedString;
> stringInserted=true;
> // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> }
>
> function insertSubstring(str, index, value) {
> return str.substr(0, index) + value + str.substr(index);
> }
>
> function printArray() {
>
> encodedString = document.getElementById("encodedText").value;
> stringMem="";oldlevel=-1;deeplevel=-1;
> for (var z = 0; z < encodedString.length; z++) {
> if (encodedString.charAt(z) == "[") {
> oldlevel=deeplevel;
> deeplevel++;
> } else if (encodedString.charAt(z) == "]") {
> oldlevel=deeplevel;
> deeplevel--;
> stringMem = stringMem.slice(0, -1);
> } else if (encodedString.charAt(z) == "*") {
> document.getElementById("decodedText").value+=stringMem+"\n";
> } else {
> stringMem += encodedString.charAt(z);
> }
> }
> }
> </script>
> <body onload="printArray();">
> <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> <br>
> <Font size="4">DEBUG</Font><br>
> <textarea id="debug" cols="80" rows="3"></textarea><br>
> <br>
> <Font size="4">INSERT IN STRUCTURE</Font><br>
> <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> <br>
> <Font size="4">STRUCTURE</Font><br>
> <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> <br>
> <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> </body>
> </html>
Pretty close now i just need to position the string/word wordlevel to be inserted on correct deeplevel using paragraphs.
<!DOCTYPE html>
<html>
<head>
<meta http-Equiv="content-type" content="text/html; charset=UTF-8">
</head>
<script>
function createStruct() {
newword=true;
beeninside=false;
oldlevel=-1;
deeplevel = -1;
wordlevel= -1;
inserted = false;
leftstruct = "[";
rightstruct = "]";
endstruct = "*";
separator = " ";
subseparator = "";
newString= "";
stringPrevMem = "";
stringMem = "";
posStructString="";
//Get values to read in
encodedString = document.getElementById("encodedText").value;
mystr = document.getElementById("inputTextToSave").value;
//Split string into words to read in
strArr = mystr.split(separator);
//Search words
for (var x = 0; x < strArr.length; x++) {
newString=strArr[x];
stringInserted=false;
searchItem(newString);
}
printArray();
}
function searchItem(newString) {
oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
while (z < encodedString.length && stringInserted==false) {
if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
// alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
// alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
} else if (encodedString.charAt(z) == "*") {
//decoded word in memory
newword=true; beeninside=false;
// alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
} else {
stringMem += encodedString.charAt(z);
newSubString=newString.substring(0,stringMem.length);
if (newSubString==stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
}
else if (newSubString>stringMem && newword==true && beeninside==false) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
newword=false;beeninside=true;
stringPrevMem = stringMem;
}
else if (newSubString<stringMem) {
oldStructLength=z;
document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
checkWhatTOInsert();
}
}
z++;
}
}
function checkWhatTOInsert(){
putString="";
if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
else {insertString = newString.substring(newSubString.length, newString.length);}
insertChar = insertString.split('');
for (var m=0;m<insertChar.length;m++){
putString+="["+insertChar[m];
}
putString+="*";
for (var m=0;m<insertChar.length;m++){
putString+="]";
}
encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
document.getElementById("encodedText").value=encodedString;
stringInserted=true;
// alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
}
function insertSubstring(str, index, value) {
return str.substr(0, index) + value + str.substr(index);
}
function printArray() {
document.getElementById("decodedText").value="";
encodedString = document.getElementById("encodedText").value;
stringMem="";oldlevel=-1;deeplevel=-1;
for (var z = 0; z < encodedString.length; z++) {
if (encodedString.charAt(z) == "[") {
oldlevel=deeplevel;
deeplevel++;
} else if (encodedString.charAt(z) == "]") {
oldlevel=deeplevel;
deeplevel--;
stringMem = stringMem.slice(0, -1);
} else if (encodedString.charAt(z) == "*") {
document.getElementById("decodedText").value+=stringMem+"\n";
} else {
stringMem += encodedString.charAt(z);
}
}
}
</script>
<body onload="printArray();">
<button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
<br>
<Font size="4">DEBUG</Font><br>
<textarea id="debug" cols="80" rows="3"></textarea><br>
<br>
<Font size="4">INSERT IN STRUCTURE</Font><br>
<textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
<br>
<Font size="4">STRUCTURE</Font><br>
<textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
<br>
<Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
<textarea id="decodedText" cols="80" rows="12"></textarea><br>
</body>
</html>
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-14 04:53 -0800 |
| Message-ID | <3049850d-1c58-4d93-95e9-cbd95aaad70b@googlegroups.com> |
| In reply to | #34350 |
Den tisdag 14 november 2017 kl. 13:52:34 UTC+1 skrev Jonas Thörnvall:
> Den tisdag 14 november 2017 kl. 13:45:45 UTC+1 skrev Jonas Thörnvall:
> > Den tisdag 14 november 2017 kl. 11:44:36 UTC+1 skrev Jonas Thörnvall:
> > > Den tisdag 14 november 2017 kl. 11:34:28 UTC+1 skrev Jonas Thörnvall:
> > > > This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
> > > >
> > > > It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
> > > >
> > > > <!DOCTYPE html>
> > > > <html>
> > > > <head>
> > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > </head>
> > > > <script>
> > > > function createStruct() {
> > > > newword=true;
> > > > beeninside=false;
> > > > oldlevel=-1;
> > > > deeplevel = -1;
> > > > wordlevel= -1;
> > > > inserted = false;
> > > > leftstruct = "[";
> > > > rightstruct = "]";
> > > > endstruct = "*";
> > > > separator = " ";
> > > > subseparator = "";
> > > > newString= "";
> > > > stringPrevMem = "";
> > > > stringMem = "";
> > > > posStructString="";
> > > > //Get values to read in
> > > > encodedString = document.getElementById("encodedText").value;
> > > > mystr = document.getElementById("inputTextToSave").value;
> > > > //Split string into words to read in
> > > > strArr = mystr.split(separator);
> > > > //Search words
> > > > for (var x = 0; x < strArr.length; x++) {
> > > >
> > > > newString=strArr[x];
> > > > stringInserted=false;
> > > > searchItem(newString);
> > > > }
> > > > printArray();
> > > > alert("closing script");
> > > > }
> > > >
> > > > function searchItem(newString) {
> > > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > > while (z < encodedString.length && stringInserted==false) {
> > > >
> > > > if (encodedString.charAt(z) == "[") {
> > > > oldlevel=deeplevel;
> > > > deeplevel++;
> > > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > } else if (encodedString.charAt(z) == "]") {
> > > > oldlevel=deeplevel;
> > > > deeplevel--;
> > > > stringMem = stringMem.slice(0, -1);
> > > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > } else if (encodedString.charAt(z) == "*") {
> > > > //decoded word in memory
> > > > newword=true; beeninside=false;
> > > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > newSubString=newString.substring(0,stringMem.length);
> > > > if (newSubString==stringMem) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > }
> > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > newword=false;beeninside=true;
> > > > stringPrevMem = stringMem;
> > > > }
> > > > else if (newSubString<stringMem) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > checkWhatTOInsert();
> > > > }
> > > > }
> > > > z++;
> > > > }
> > > > }
> > > >
> > > >
> > > > function checkWhatTOInsert(){
> > > > putString="";
> > > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > > >
> > > > insertChar = insertString.split('');
> > > > for (var m=0;m<insertChar.length;m++){
> > > > putString+="["+insertChar[m];
> > > > }
> > > > putString+="*";
> > > > for (var m=0;m<insertChar.length;m++){
> > > > putString+="]";
> > > > }
> > > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > > document.getElementById("encodedText").value=encodedString;
> > > > stringInserted=true;
> > > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > > }
> > > >
> > > > function insertSubstring(str, index, value) {
> > > > return str.substr(0, index) + value + str.substr(index);
> > > > }
> > > >
> > > > function printArray() {
> > > >
> > > > encodedString = document.getElementById("encodedText").value;
> > > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > > for (var z = 0; z < encodedString.length; z++) {
> > > > if (encodedString.charAt(z) == "[") {
> > > > oldlevel=deeplevel;
> > > > deeplevel++;
> > > > } else if (encodedString.charAt(z) == "]") {
> > > > oldlevel=deeplevel;
> > > > deeplevel--;
> > > > stringMem = stringMem.slice(0, -1);
> > > > } else if (encodedString.charAt(z) == "*") {
> > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > >
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > }
> > > > }
> > > > }
> > > > </script>
> > > > <body onload="printArray();">
> > > > <form onSubmit="createStruct();">
> > > > <input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
> > > > </form>
> > > > <br>
> > > > <Font size="4">DEBUG</Font><br>
> > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > <br>
> > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > > <br>
> > > > <Font size="4">STRUCTURE</Font><br>
> > > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > > <br>
> > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > </body>
> > > > </html>
> > >
> > > I can't see how these could do anything wrong, writing to textarea what am i missing?
> > >
> > > document.getElementById("encodedText").value=encodedString;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> >
> > Changed to button problem fixed.
> >
> > <!DOCTYPE html>
> > <html>
> > <head>
> > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > </head>
> > <script>
> > function createStruct() {
> > newword=true;
> > beeninside=false;
> > oldlevel=-1;
> > deeplevel = -1;
> > wordlevel= -1;
> > inserted = false;
> > leftstruct = "[";
> > rightstruct = "]";
> > endstruct = "*";
> > separator = " ";
> > subseparator = "";
> > newString= "";
> > stringPrevMem = "";
> > stringMem = "";
> > posStructString="";
> > //Get values to read in
> > encodedString = document.getElementById("encodedText").value;
> > mystr = document.getElementById("inputTextToSave").value;
> > //Split string into words to read in
> > strArr = mystr.split(separator);
> > //Search words
> > for (var x = 0; x < strArr.length; x++) {
> > newString=strArr[x];
> > stringInserted=false;
> > searchItem(newString);
> > printArray();
> > }
> >
> > alert("closing script");
> > }
> >
> > function searchItem(newString) {
> > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > while (z < encodedString.length && stringInserted==false) {
> >
> > if (encodedString.charAt(z) == "[") {
> > oldlevel=deeplevel;
> > deeplevel++;
> > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > } else if (encodedString.charAt(z) == "]") {
> > oldlevel=deeplevel;
> > deeplevel--;
> > stringMem = stringMem.slice(0, -1);
> > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > } else if (encodedString.charAt(z) == "*") {
> > //decoded word in memory
> > newword=true; beeninside=false;
> > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > } else {
> > stringMem += encodedString.charAt(z);
> > newSubString=newString.substring(0,stringMem.length);
> > if (newSubString==stringMem) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > }
> > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > newword=false;beeninside=true;
> > stringPrevMem = stringMem;
> > }
> > else if (newSubString<stringMem) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > checkWhatTOInsert();
> > }
> > }
> > z++;
> > }
> > }
> >
> >
> > function checkWhatTOInsert(){
> > putString="";
> > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > else {insertString = newString.substring(newSubString.length, newString.length);}
> >
> > insertChar = insertString.split('');
> > for (var m=0;m<insertChar.length;m++){
> > putString+="["+insertChar[m];
> > }
> > putString+="*";
> > for (var m=0;m<insertChar.length;m++){
> > putString+="]";
> > }
> > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > document.getElementById("encodedText").value=encodedString;
> > stringInserted=true;
> > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > }
> >
> > function insertSubstring(str, index, value) {
> > return str.substr(0, index) + value + str.substr(index);
> > }
> >
> > function printArray() {
> >
> > encodedString = document.getElementById("encodedText").value;
> > stringMem="";oldlevel=-1;deeplevel=-1;
> > for (var z = 0; z < encodedString.length; z++) {
> > if (encodedString.charAt(z) == "[") {
> > oldlevel=deeplevel;
> > deeplevel++;
> > } else if (encodedString.charAt(z) == "]") {
> > oldlevel=deeplevel;
> > deeplevel--;
> > stringMem = stringMem.slice(0, -1);
> > } else if (encodedString.charAt(z) == "*") {
> > document.getElementById("decodedText").value+=stringMem+"\n";
> > } else {
> > stringMem += encodedString.charAt(z);
> > }
> > }
> > }
> > </script>
> > <body onload="printArray();">
> > <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> > <br>
> > <Font size="4">DEBUG</Font><br>
> > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > <br>
> > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > <br>
> > <Font size="4">STRUCTURE</Font><br>
> > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > <br>
> > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > </body>
> > </html>
>
> Pretty close now i just need to position the string/word wordlevel to be inserted on correct deeplevel using paragraphs.
>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> </head>
> <script>
> function createStruct() {
> newword=true;
> beeninside=false;
> oldlevel=-1;
> deeplevel = -1;
> wordlevel= -1;
> inserted = false;
> leftstruct = "[";
> rightstruct = "]";
> endstruct = "*";
> separator = " ";
> subseparator = "";
> newString= "";
> stringPrevMem = "";
> stringMem = "";
> posStructString="";
> //Get values to read in
> encodedString = document.getElementById("encodedText").value;
> mystr = document.getElementById("inputTextToSave").value;
> //Split string into words to read in
> strArr = mystr.split(separator);
> //Search words
> for (var x = 0; x < strArr.length; x++) {
> newString=strArr[x];
> stringInserted=false;
> searchItem(newString);
>
> }
> printArray();
>
> }
>
> function searchItem(newString) {
> oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> while (z < encodedString.length && stringInserted==false) {
>
> if (encodedString.charAt(z) == "[") {
> oldlevel=deeplevel;
> deeplevel++;
> // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> } else if (encodedString.charAt(z) == "]") {
> oldlevel=deeplevel;
> deeplevel--;
> stringMem = stringMem.slice(0, -1);
> // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> } else if (encodedString.charAt(z) == "*") {
> //decoded word in memory
> newword=true; beeninside=false;
> // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> } else {
> stringMem += encodedString.charAt(z);
> newSubString=newString.substring(0,stringMem.length);
> if (newSubString==stringMem) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> }
> else if (newSubString>stringMem && newword==true && beeninside==false) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> newword=false;beeninside=true;
> stringPrevMem = stringMem;
> }
> else if (newSubString<stringMem) {
> oldStructLength=z;
> document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> checkWhatTOInsert();
> }
> }
> z++;
> }
> }
>
>
> function checkWhatTOInsert(){
> putString="";
> if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> else {insertString = newString.substring(newSubString.length, newString.length);}
>
> insertChar = insertString.split('');
> for (var m=0;m<insertChar.length;m++){
> putString+="["+insertChar[m];
> }
> putString+="*";
> for (var m=0;m<insertChar.length;m++){
> putString+="]";
> }
> encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> document.getElementById("encodedText").value=encodedString;
> stringInserted=true;
> // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> }
>
> function insertSubstring(str, index, value) {
> return str.substr(0, index) + value + str.substr(index);
> }
>
> function printArray() {
> document.getElementById("decodedText").value="";
> encodedString = document.getElementById("encodedText").value;
> stringMem="";oldlevel=-1;deeplevel=-1;
> for (var z = 0; z < encodedString.length; z++) {
> if (encodedString.charAt(z) == "[") {
> oldlevel=deeplevel;
> deeplevel++;
> } else if (encodedString.charAt(z) == "]") {
> oldlevel=deeplevel;
> deeplevel--;
> stringMem = stringMem.slice(0, -1);
> } else if (encodedString.charAt(z) == "*") {
> document.getElementById("decodedText").value+=stringMem+"\n";
> } else {
> stringMem += encodedString.charAt(z);
> }
> }
> }
> </script>
> <body onload="printArray();">
> <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> <br>
> <Font size="4">DEBUG</Font><br>
> <textarea id="debug" cols="80" rows="3"></textarea><br>
> <br>
> <Font size="4">INSERT IN STRUCTURE</Font><br>
> <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> <br>
> <Font size="4">STRUCTURE</Font><br>
> <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> <br>
> <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> </body>
> </html>
The case with words that actually smaller or bigger in array are special cases.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-14 05:33 -0800 |
| Message-ID | <20b214ac-a47c-46ef-84b2-0e1dabf57be2@googlegroups.com> |
| In reply to | #34351 |
Den tisdag 14 november 2017 kl. 13:53:48 UTC+1 skrev Jonas Thörnvall:
> Den tisdag 14 november 2017 kl. 13:52:34 UTC+1 skrev Jonas Thörnvall:
> > Den tisdag 14 november 2017 kl. 13:45:45 UTC+1 skrev Jonas Thörnvall:
> > > Den tisdag 14 november 2017 kl. 11:44:36 UTC+1 skrev Jonas Thörnvall:
> > > > Den tisdag 14 november 2017 kl. 11:34:28 UTC+1 skrev Jonas Thörnvall:
> > > > > This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
> > > > >
> > > > > It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
> > > > >
> > > > > <!DOCTYPE html>
> > > > > <html>
> > > > > <head>
> > > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > > </head>
> > > > > <script>
> > > > > function createStruct() {
> > > > > newword=true;
> > > > > beeninside=false;
> > > > > oldlevel=-1;
> > > > > deeplevel = -1;
> > > > > wordlevel= -1;
> > > > > inserted = false;
> > > > > leftstruct = "[";
> > > > > rightstruct = "]";
> > > > > endstruct = "*";
> > > > > separator = " ";
> > > > > subseparator = "";
> > > > > newString= "";
> > > > > stringPrevMem = "";
> > > > > stringMem = "";
> > > > > posStructString="";
> > > > > //Get values to read in
> > > > > encodedString = document.getElementById("encodedText").value;
> > > > > mystr = document.getElementById("inputTextToSave").value;
> > > > > //Split string into words to read in
> > > > > strArr = mystr.split(separator);
> > > > > //Search words
> > > > > for (var x = 0; x < strArr.length; x++) {
> > > > >
> > > > > newString=strArr[x];
> > > > > stringInserted=false;
> > > > > searchItem(newString);
> > > > > }
> > > > > printArray();
> > > > > alert("closing script");
> > > > > }
> > > > >
> > > > > function searchItem(newString) {
> > > > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > > > while (z < encodedString.length && stringInserted==false) {
> > > > >
> > > > > if (encodedString.charAt(z) == "[") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel++;
> > > > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel--;
> > > > > stringMem = stringMem.slice(0, -1);
> > > > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > //decoded word in memory
> > > > > newword=true; beeninside=false;
> > > > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > > > } else {
> > > > > stringMem += encodedString.charAt(z);
> > > > > newSubString=newString.substring(0,stringMem.length);
> > > > > if (newSubString==stringMem) {
> > > > > oldStructLength=z;
> > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > }
> > > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > > oldStructLength=z;
> > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > newword=false;beeninside=true;
> > > > > stringPrevMem = stringMem;
> > > > > }
> > > > > else if (newSubString<stringMem) {
> > > > > oldStructLength=z;
> > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > checkWhatTOInsert();
> > > > > }
> > > > > }
> > > > > z++;
> > > > > }
> > > > > }
> > > > >
> > > > >
> > > > > function checkWhatTOInsert(){
> > > > > putString="";
> > > > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > > > >
> > > > > insertChar = insertString.split('');
> > > > > for (var m=0;m<insertChar.length;m++){
> > > > > putString+="["+insertChar[m];
> > > > > }
> > > > > putString+="*";
> > > > > for (var m=0;m<insertChar.length;m++){
> > > > > putString+="]";
> > > > > }
> > > > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > > > document.getElementById("encodedText").value=encodedString;
> > > > > stringInserted=true;
> > > > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > > > }
> > > > >
> > > > > function insertSubstring(str, index, value) {
> > > > > return str.substr(0, index) + value + str.substr(index);
> > > > > }
> > > > >
> > > > > function printArray() {
> > > > >
> > > > > encodedString = document.getElementById("encodedText").value;
> > > > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > > > for (var z = 0; z < encodedString.length; z++) {
> > > > > if (encodedString.charAt(z) == "[") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel++;
> > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel--;
> > > > > stringMem = stringMem.slice(0, -1);
> > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > > >
> > > > > } else {
> > > > > stringMem += encodedString.charAt(z);
> > > > > }
> > > > > }
> > > > > }
> > > > > </script>
> > > > > <body onload="printArray();">
> > > > > <form onSubmit="createStruct();">
> > > > > <input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
> > > > > </form>
> > > > > <br>
> > > > > <Font size="4">DEBUG</Font><br>
> > > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > > <br>
> > > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > > > <br>
> > > > > <Font size="4">STRUCTURE</Font><br>
> > > > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > > > <br>
> > > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > > </body>
> > > > > </html>
> > > >
> > > > I can't see how these could do anything wrong, writing to textarea what am i missing?
> > > >
> > > > document.getElementById("encodedText").value=encodedString;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > >
> > > Changed to button problem fixed.
> > >
> > > <!DOCTYPE html>
> > > <html>
> > > <head>
> > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > </head>
> > > <script>
> > > function createStruct() {
> > > newword=true;
> > > beeninside=false;
> > > oldlevel=-1;
> > > deeplevel = -1;
> > > wordlevel= -1;
> > > inserted = false;
> > > leftstruct = "[";
> > > rightstruct = "]";
> > > endstruct = "*";
> > > separator = " ";
> > > subseparator = "";
> > > newString= "";
> > > stringPrevMem = "";
> > > stringMem = "";
> > > posStructString="";
> > > //Get values to read in
> > > encodedString = document.getElementById("encodedText").value;
> > > mystr = document.getElementById("inputTextToSave").value;
> > > //Split string into words to read in
> > > strArr = mystr.split(separator);
> > > //Search words
> > > for (var x = 0; x < strArr.length; x++) {
> > > newString=strArr[x];
> > > stringInserted=false;
> > > searchItem(newString);
> > > printArray();
> > > }
> > >
> > > alert("closing script");
> > > }
> > >
> > > function searchItem(newString) {
> > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > while (z < encodedString.length && stringInserted==false) {
> > >
> > > if (encodedString.charAt(z) == "[") {
> > > oldlevel=deeplevel;
> > > deeplevel++;
> > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > } else if (encodedString.charAt(z) == "]") {
> > > oldlevel=deeplevel;
> > > deeplevel--;
> > > stringMem = stringMem.slice(0, -1);
> > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > } else if (encodedString.charAt(z) == "*") {
> > > //decoded word in memory
> > > newword=true; beeninside=false;
> > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > newSubString=newString.substring(0,stringMem.length);
> > > if (newSubString==stringMem) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > }
> > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > newword=false;beeninside=true;
> > > stringPrevMem = stringMem;
> > > }
> > > else if (newSubString<stringMem) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > checkWhatTOInsert();
> > > }
> > > }
> > > z++;
> > > }
> > > }
> > >
> > >
> > > function checkWhatTOInsert(){
> > > putString="";
> > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > >
> > > insertChar = insertString.split('');
> > > for (var m=0;m<insertChar.length;m++){
> > > putString+="["+insertChar[m];
> > > }
> > > putString+="*";
> > > for (var m=0;m<insertChar.length;m++){
> > > putString+="]";
> > > }
> > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > document.getElementById("encodedText").value=encodedString;
> > > stringInserted=true;
> > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > }
> > >
> > > function insertSubstring(str, index, value) {
> > > return str.substr(0, index) + value + str.substr(index);
> > > }
> > >
> > > function printArray() {
> > >
> > > encodedString = document.getElementById("encodedText").value;
> > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > for (var z = 0; z < encodedString.length; z++) {
> > > if (encodedString.charAt(z) == "[") {
> > > oldlevel=deeplevel;
> > > deeplevel++;
> > > } else if (encodedString.charAt(z) == "]") {
> > > oldlevel=deeplevel;
> > > deeplevel--;
> > > stringMem = stringMem.slice(0, -1);
> > > } else if (encodedString.charAt(z) == "*") {
> > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > }
> > > }
> > > }
> > > </script>
> > > <body onload="printArray();">
> > > <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> > > <br>
> > > <Font size="4">DEBUG</Font><br>
> > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > <br>
> > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > <br>
> > > <Font size="4">STRUCTURE</Font><br>
> > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > <br>
> > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > </body>
> > > </html>
> >
> > Pretty close now i just need to position the string/word wordlevel to be inserted on correct deeplevel using paragraphs.
> >
> > <!DOCTYPE html>
> > <html>
> > <head>
> > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > </head>
> > <script>
> > function createStruct() {
> > newword=true;
> > beeninside=false;
> > oldlevel=-1;
> > deeplevel = -1;
> > wordlevel= -1;
> > inserted = false;
> > leftstruct = "[";
> > rightstruct = "]";
> > endstruct = "*";
> > separator = " ";
> > subseparator = "";
> > newString= "";
> > stringPrevMem = "";
> > stringMem = "";
> > posStructString="";
> > //Get values to read in
> > encodedString = document.getElementById("encodedText").value;
> > mystr = document.getElementById("inputTextToSave").value;
> > //Split string into words to read in
> > strArr = mystr.split(separator);
> > //Search words
> > for (var x = 0; x < strArr.length; x++) {
> > newString=strArr[x];
> > stringInserted=false;
> > searchItem(newString);
> >
> > }
> > printArray();
> >
> > }
> >
> > function searchItem(newString) {
> > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > while (z < encodedString.length && stringInserted==false) {
> >
> > if (encodedString.charAt(z) == "[") {
> > oldlevel=deeplevel;
> > deeplevel++;
> > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > } else if (encodedString.charAt(z) == "]") {
> > oldlevel=deeplevel;
> > deeplevel--;
> > stringMem = stringMem.slice(0, -1);
> > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > } else if (encodedString.charAt(z) == "*") {
> > //decoded word in memory
> > newword=true; beeninside=false;
> > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > } else {
> > stringMem += encodedString.charAt(z);
> > newSubString=newString.substring(0,stringMem.length);
> > if (newSubString==stringMem) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > }
> > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > newword=false;beeninside=true;
> > stringPrevMem = stringMem;
> > }
> > else if (newSubString<stringMem) {
> > oldStructLength=z;
> > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > checkWhatTOInsert();
> > }
> > }
> > z++;
> > }
> > }
> >
> >
> > function checkWhatTOInsert(){
> > putString="";
> > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > else {insertString = newString.substring(newSubString.length, newString.length);}
> >
> > insertChar = insertString.split('');
> > for (var m=0;m<insertChar.length;m++){
> > putString+="["+insertChar[m];
> > }
> > putString+="*";
> > for (var m=0;m<insertChar.length;m++){
> > putString+="]";
> > }
> > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > document.getElementById("encodedText").value=encodedString;
> > stringInserted=true;
> > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > }
> >
> > function insertSubstring(str, index, value) {
> > return str.substr(0, index) + value + str.substr(index);
> > }
> >
> > function printArray() {
> > document.getElementById("decodedText").value="";
> > encodedString = document.getElementById("encodedText").value;
> > stringMem="";oldlevel=-1;deeplevel=-1;
> > for (var z = 0; z < encodedString.length; z++) {
> > if (encodedString.charAt(z) == "[") {
> > oldlevel=deeplevel;
> > deeplevel++;
> > } else if (encodedString.charAt(z) == "]") {
> > oldlevel=deeplevel;
> > deeplevel--;
> > stringMem = stringMem.slice(0, -1);
> > } else if (encodedString.charAt(z) == "*") {
> > document.getElementById("decodedText").value+=stringMem+"\n";
> > } else {
> > stringMem += encodedString.charAt(z);
> > }
> > }
> > }
> > </script>
> > <body onload="printArray();">
> > <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> > <br>
> > <Font size="4">DEBUG</Font><br>
> > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > <br>
> > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > <br>
> > <Font size="4">STRUCTURE</Font><br>
> > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > <br>
> > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > </body>
> > </html>
>
> The case with words that actually smaller or bigger in array are special cases.
http://anybase.co.nf/insert/chessbook.html
I think it will work tomorrow and put them correct between paragraphs ...maybe i will use it to create a chessbok where i can read in chessgames in an hieraki and each position gets a probability of win.
It is sort of treestructure without restrictions except for memory, it is like treestucture without depth restrictions. And it don't allocate any memory, you really do not keep the full tree in memory just read forward as you search in it. Right now it read the full structure into memory, to insert new string items.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-14 12:04 -0800 |
| Message-ID | <1e178ceb-86c9-4d1d-b1fb-62938506a33b@googlegroups.com> |
| In reply to | #34352 |
Den tisdag 14 november 2017 kl. 14:33:38 UTC+1 skrev Jonas Thörnvall:
> Den tisdag 14 november 2017 kl. 13:53:48 UTC+1 skrev Jonas Thörnvall:
> > Den tisdag 14 november 2017 kl. 13:52:34 UTC+1 skrev Jonas Thörnvall:
> > > Den tisdag 14 november 2017 kl. 13:45:45 UTC+1 skrev Jonas Thörnvall:
> > > > Den tisdag 14 november 2017 kl. 11:44:36 UTC+1 skrev Jonas Thörnvall:
> > > > > Den tisdag 14 november 2017 kl. 11:34:28 UTC+1 skrev Jonas Thörnvall:
> > > > > > This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
> > > > > >
> > > > > > It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
> > > > > >
> > > > > > <!DOCTYPE html>
> > > > > > <html>
> > > > > > <head>
> > > > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > > > </head>
> > > > > > <script>
> > > > > > function createStruct() {
> > > > > > newword=true;
> > > > > > beeninside=false;
> > > > > > oldlevel=-1;
> > > > > > deeplevel = -1;
> > > > > > wordlevel= -1;
> > > > > > inserted = false;
> > > > > > leftstruct = "[";
> > > > > > rightstruct = "]";
> > > > > > endstruct = "*";
> > > > > > separator = " ";
> > > > > > subseparator = "";
> > > > > > newString= "";
> > > > > > stringPrevMem = "";
> > > > > > stringMem = "";
> > > > > > posStructString="";
> > > > > > //Get values to read in
> > > > > > encodedString = document.getElementById("encodedText").value;
> > > > > > mystr = document.getElementById("inputTextToSave").value;
> > > > > > //Split string into words to read in
> > > > > > strArr = mystr.split(separator);
> > > > > > //Search words
> > > > > > for (var x = 0; x < strArr.length; x++) {
> > > > > >
> > > > > > newString=strArr[x];
> > > > > > stringInserted=false;
> > > > > > searchItem(newString);
> > > > > > }
> > > > > > printArray();
> > > > > > alert("closing script");
> > > > > > }
> > > > > >
> > > > > > function searchItem(newString) {
> > > > > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > > > > while (z < encodedString.length && stringInserted==false) {
> > > > > >
> > > > > > if (encodedString.charAt(z) == "[") {
> > > > > > oldlevel=deeplevel;
> > > > > > deeplevel++;
> > > > > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > > oldlevel=deeplevel;
> > > > > > deeplevel--;
> > > > > > stringMem = stringMem.slice(0, -1);
> > > > > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > > //decoded word in memory
> > > > > > newword=true; beeninside=false;
> > > > > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > > > > } else {
> > > > > > stringMem += encodedString.charAt(z);
> > > > > > newSubString=newString.substring(0,stringMem.length);
> > > > > > if (newSubString==stringMem) {
> > > > > > oldStructLength=z;
> > > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > > }
> > > > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > > > oldStructLength=z;
> > > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > > newword=false;beeninside=true;
> > > > > > stringPrevMem = stringMem;
> > > > > > }
> > > > > > else if (newSubString<stringMem) {
> > > > > > oldStructLength=z;
> > > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > > checkWhatTOInsert();
> > > > > > }
> > > > > > }
> > > > > > z++;
> > > > > > }
> > > > > > }
> > > > > >
> > > > > >
> > > > > > function checkWhatTOInsert(){
> > > > > > putString="";
> > > > > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > > > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > > > > >
> > > > > > insertChar = insertString.split('');
> > > > > > for (var m=0;m<insertChar.length;m++){
> > > > > > putString+="["+insertChar[m];
> > > > > > }
> > > > > > putString+="*";
> > > > > > for (var m=0;m<insertChar.length;m++){
> > > > > > putString+="]";
> > > > > > }
> > > > > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > > > > document.getElementById("encodedText").value=encodedString;
> > > > > > stringInserted=true;
> > > > > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > > > > }
> > > > > >
> > > > > > function insertSubstring(str, index, value) {
> > > > > > return str.substr(0, index) + value + str.substr(index);
> > > > > > }
> > > > > >
> > > > > > function printArray() {
> > > > > >
> > > > > > encodedString = document.getElementById("encodedText").value;
> > > > > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > > > > for (var z = 0; z < encodedString.length; z++) {
> > > > > > if (encodedString.charAt(z) == "[") {
> > > > > > oldlevel=deeplevel;
> > > > > > deeplevel++;
> > > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > > oldlevel=deeplevel;
> > > > > > deeplevel--;
> > > > > > stringMem = stringMem.slice(0, -1);
> > > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > > > >
> > > > > > } else {
> > > > > > stringMem += encodedString.charAt(z);
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > > </script>
> > > > > > <body onload="printArray();">
> > > > > > <form onSubmit="createStruct();">
> > > > > > <input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
> > > > > > </form>
> > > > > > <br>
> > > > > > <Font size="4">DEBUG</Font><br>
> > > > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > > > <br>
> > > > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > > > > <br>
> > > > > > <Font size="4">STRUCTURE</Font><br>
> > > > > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > > > > <br>
> > > > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > > > </body>
> > > > > > </html>
> > > > >
> > > > > I can't see how these could do anything wrong, writing to textarea what am i missing?
> > > > >
> > > > > document.getElementById("encodedText").value=encodedString;
> > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > >
> > > > Changed to button problem fixed.
> > > >
> > > > <!DOCTYPE html>
> > > > <html>
> > > > <head>
> > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > </head>
> > > > <script>
> > > > function createStruct() {
> > > > newword=true;
> > > > beeninside=false;
> > > > oldlevel=-1;
> > > > deeplevel = -1;
> > > > wordlevel= -1;
> > > > inserted = false;
> > > > leftstruct = "[";
> > > > rightstruct = "]";
> > > > endstruct = "*";
> > > > separator = " ";
> > > > subseparator = "";
> > > > newString= "";
> > > > stringPrevMem = "";
> > > > stringMem = "";
> > > > posStructString="";
> > > > //Get values to read in
> > > > encodedString = document.getElementById("encodedText").value;
> > > > mystr = document.getElementById("inputTextToSave").value;
> > > > //Split string into words to read in
> > > > strArr = mystr.split(separator);
> > > > //Search words
> > > > for (var x = 0; x < strArr.length; x++) {
> > > > newString=strArr[x];
> > > > stringInserted=false;
> > > > searchItem(newString);
> > > > printArray();
> > > > }
> > > >
> > > > alert("closing script");
> > > > }
> > > >
> > > > function searchItem(newString) {
> > > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > > while (z < encodedString.length && stringInserted==false) {
> > > >
> > > > if (encodedString.charAt(z) == "[") {
> > > > oldlevel=deeplevel;
> > > > deeplevel++;
> > > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > } else if (encodedString.charAt(z) == "]") {
> > > > oldlevel=deeplevel;
> > > > deeplevel--;
> > > > stringMem = stringMem.slice(0, -1);
> > > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > } else if (encodedString.charAt(z) == "*") {
> > > > //decoded word in memory
> > > > newword=true; beeninside=false;
> > > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > newSubString=newString.substring(0,stringMem.length);
> > > > if (newSubString==stringMem) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > }
> > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > newword=false;beeninside=true;
> > > > stringPrevMem = stringMem;
> > > > }
> > > > else if (newSubString<stringMem) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > checkWhatTOInsert();
> > > > }
> > > > }
> > > > z++;
> > > > }
> > > > }
> > > >
> > > >
> > > > function checkWhatTOInsert(){
> > > > putString="";
> > > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > > >
> > > > insertChar = insertString.split('');
> > > > for (var m=0;m<insertChar.length;m++){
> > > > putString+="["+insertChar[m];
> > > > }
> > > > putString+="*";
> > > > for (var m=0;m<insertChar.length;m++){
> > > > putString+="]";
> > > > }
> > > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > > document.getElementById("encodedText").value=encodedString;
> > > > stringInserted=true;
> > > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > > }
> > > >
> > > > function insertSubstring(str, index, value) {
> > > > return str.substr(0, index) + value + str.substr(index);
> > > > }
> > > >
> > > > function printArray() {
> > > >
> > > > encodedString = document.getElementById("encodedText").value;
> > > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > > for (var z = 0; z < encodedString.length; z++) {
> > > > if (encodedString.charAt(z) == "[") {
> > > > oldlevel=deeplevel;
> > > > deeplevel++;
> > > > } else if (encodedString.charAt(z) == "]") {
> > > > oldlevel=deeplevel;
> > > > deeplevel--;
> > > > stringMem = stringMem.slice(0, -1);
> > > > } else if (encodedString.charAt(z) == "*") {
> > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > }
> > > > }
> > > > }
> > > > </script>
> > > > <body onload="printArray();">
> > > > <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> > > > <br>
> > > > <Font size="4">DEBUG</Font><br>
> > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > <br>
> > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > > <br>
> > > > <Font size="4">STRUCTURE</Font><br>
> > > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > > <br>
> > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > </body>
> > > > </html>
> > >
> > > Pretty close now i just need to position the string/word wordlevel to be inserted on correct deeplevel using paragraphs.
> > >
> > > <!DOCTYPE html>
> > > <html>
> > > <head>
> > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > </head>
> > > <script>
> > > function createStruct() {
> > > newword=true;
> > > beeninside=false;
> > > oldlevel=-1;
> > > deeplevel = -1;
> > > wordlevel= -1;
> > > inserted = false;
> > > leftstruct = "[";
> > > rightstruct = "]";
> > > endstruct = "*";
> > > separator = " ";
> > > subseparator = "";
> > > newString= "";
> > > stringPrevMem = "";
> > > stringMem = "";
> > > posStructString="";
> > > //Get values to read in
> > > encodedString = document.getElementById("encodedText").value;
> > > mystr = document.getElementById("inputTextToSave").value;
> > > //Split string into words to read in
> > > strArr = mystr.split(separator);
> > > //Search words
> > > for (var x = 0; x < strArr.length; x++) {
> > > newString=strArr[x];
> > > stringInserted=false;
> > > searchItem(newString);
> > >
> > > }
> > > printArray();
> > >
> > > }
> > >
> > > function searchItem(newString) {
> > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > while (z < encodedString.length && stringInserted==false) {
> > >
> > > if (encodedString.charAt(z) == "[") {
> > > oldlevel=deeplevel;
> > > deeplevel++;
> > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > } else if (encodedString.charAt(z) == "]") {
> > > oldlevel=deeplevel;
> > > deeplevel--;
> > > stringMem = stringMem.slice(0, -1);
> > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > } else if (encodedString.charAt(z) == "*") {
> > > //decoded word in memory
> > > newword=true; beeninside=false;
> > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > newSubString=newString.substring(0,stringMem.length);
> > > if (newSubString==stringMem) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > }
> > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > newword=false;beeninside=true;
> > > stringPrevMem = stringMem;
> > > }
> > > else if (newSubString<stringMem) {
> > > oldStructLength=z;
> > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > checkWhatTOInsert();
> > > }
> > > }
> > > z++;
> > > }
> > > }
> > >
> > >
> > > function checkWhatTOInsert(){
> > > putString="";
> > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > >
> > > insertChar = insertString.split('');
> > > for (var m=0;m<insertChar.length;m++){
> > > putString+="["+insertChar[m];
> > > }
> > > putString+="*";
> > > for (var m=0;m<insertChar.length;m++){
> > > putString+="]";
> > > }
> > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > document.getElementById("encodedText").value=encodedString;
> > > stringInserted=true;
> > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > }
> > >
> > > function insertSubstring(str, index, value) {
> > > return str.substr(0, index) + value + str.substr(index);
> > > }
> > >
> > > function printArray() {
> > > document.getElementById("decodedText").value="";
> > > encodedString = document.getElementById("encodedText").value;
> > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > for (var z = 0; z < encodedString.length; z++) {
> > > if (encodedString.charAt(z) == "[") {
> > > oldlevel=deeplevel;
> > > deeplevel++;
> > > } else if (encodedString.charAt(z) == "]") {
> > > oldlevel=deeplevel;
> > > deeplevel--;
> > > stringMem = stringMem.slice(0, -1);
> > > } else if (encodedString.charAt(z) == "*") {
> > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > } else {
> > > stringMem += encodedString.charAt(z);
> > > }
> > > }
> > > }
> > > </script>
> > > <body onload="printArray();">
> > > <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> > > <br>
> > > <Font size="4">DEBUG</Font><br>
> > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > <br>
> > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > <br>
> > > <Font size="4">STRUCTURE</Font><br>
> > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > <br>
> > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > </body>
> > > </html>
> >
> > The case with words that actually smaller or bigger in array are special cases.
>
> http://anybase.co.nf/insert/chessbook.html
>
> I think it will work tomorrow and put them correct between paragraphs ...maybe i will use it to create a chessbok where i can read in chessgames in an hieraki and each position gets a probability of win.
>
> It is sort of treestructure without restrictions except for memory, it is like treestucture without depth restrictions. And it don't allocate any memory, you really do not keep the full tree in memory just read forward as you search in it. Right now it read the full structure into memory, to insert new string items.
An AI that work on 1KB of memory, doing alot of swapping....
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2017-11-14 16:52 -0800 |
| Message-ID | <772ed27b-f95a-4725-b41e-32eb24ee4909@googlegroups.com> |
| In reply to | #34354 |
Den tisdag 14 november 2017 kl. 21:04:15 UTC+1 skrev Jonas Thörnvall:
> Den tisdag 14 november 2017 kl. 14:33:38 UTC+1 skrev Jonas Thörnvall:
> > Den tisdag 14 november 2017 kl. 13:53:48 UTC+1 skrev Jonas Thörnvall:
> > > Den tisdag 14 november 2017 kl. 13:52:34 UTC+1 skrev Jonas Thörnvall:
> > > > Den tisdag 14 november 2017 kl. 13:45:45 UTC+1 skrev Jonas Thörnvall:
> > > > > Den tisdag 14 november 2017 kl. 11:44:36 UTC+1 skrev Jonas Thörnvall:
> > > > > > Den tisdag 14 november 2017 kl. 11:34:28 UTC+1 skrev Jonas Thörnvall:
> > > > > > > This is work in progress, so don't care about the actual code it work forwars slow, but why does the script reload after it ended?
> > > > > > >
> > > > > > > It makes it impossible to debug, because it automatically reload i was thinking there was so special chars hidden that make it reload, or am i writing to a textfield id that do not exist but i checked.
> > > > > > >
> > > > > > > <!DOCTYPE html>
> > > > > > > <html>
> > > > > > > <head>
> > > > > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > > > > </head>
> > > > > > > <script>
> > > > > > > function createStruct() {
> > > > > > > newword=true;
> > > > > > > beeninside=false;
> > > > > > > oldlevel=-1;
> > > > > > > deeplevel = -1;
> > > > > > > wordlevel= -1;
> > > > > > > inserted = false;
> > > > > > > leftstruct = "[";
> > > > > > > rightstruct = "]";
> > > > > > > endstruct = "*";
> > > > > > > separator = " ";
> > > > > > > subseparator = "";
> > > > > > > newString= "";
> > > > > > > stringPrevMem = "";
> > > > > > > stringMem = "";
> > > > > > > posStructString="";
> > > > > > > //Get values to read in
> > > > > > > encodedString = document.getElementById("encodedText").value;
> > > > > > > mystr = document.getElementById("inputTextToSave").value;
> > > > > > > //Split string into words to read in
> > > > > > > strArr = mystr.split(separator);
> > > > > > > //Search words
> > > > > > > for (var x = 0; x < strArr.length; x++) {
> > > > > > >
> > > > > > > newString=strArr[x];
> > > > > > > stringInserted=false;
> > > > > > > searchItem(newString);
> > > > > > > }
> > > > > > > printArray();
> > > > > > > alert("closing script");
> > > > > > > }
> > > > > > >
> > > > > > > function searchItem(newString) {
> > > > > > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > > > > > while (z < encodedString.length && stringInserted==false) {
> > > > > > >
> > > > > > > if (encodedString.charAt(z) == "[") {
> > > > > > > oldlevel=deeplevel;
> > > > > > > deeplevel++;
> > > > > > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > > > oldlevel=deeplevel;
> > > > > > > deeplevel--;
> > > > > > > stringMem = stringMem.slice(0, -1);
> > > > > > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > > > //decoded word in memory
> > > > > > > newword=true; beeninside=false;
> > > > > > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > > > > > } else {
> > > > > > > stringMem += encodedString.charAt(z);
> > > > > > > newSubString=newString.substring(0,stringMem.length);
> > > > > > > if (newSubString==stringMem) {
> > > > > > > oldStructLength=z;
> > > > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > > > }
> > > > > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > > > > oldStructLength=z;
> > > > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > > > newword=false;beeninside=true;
> > > > > > > stringPrevMem = stringMem;
> > > > > > > }
> > > > > > > else if (newSubString<stringMem) {
> > > > > > > oldStructLength=z;
> > > > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > > > checkWhatTOInsert();
> > > > > > > }
> > > > > > > }
> > > > > > > z++;
> > > > > > > }
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > > function checkWhatTOInsert(){
> > > > > > > putString="";
> > > > > > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > > > > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > > > > > >
> > > > > > > insertChar = insertString.split('');
> > > > > > > for (var m=0;m<insertChar.length;m++){
> > > > > > > putString+="["+insertChar[m];
> > > > > > > }
> > > > > > > putString+="*";
> > > > > > > for (var m=0;m<insertChar.length;m++){
> > > > > > > putString+="]";
> > > > > > > }
> > > > > > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > > > > > document.getElementById("encodedText").value=encodedString;
> > > > > > > stringInserted=true;
> > > > > > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > > > > > }
> > > > > > >
> > > > > > > function insertSubstring(str, index, value) {
> > > > > > > return str.substr(0, index) + value + str.substr(index);
> > > > > > > }
> > > > > > >
> > > > > > > function printArray() {
> > > > > > >
> > > > > > > encodedString = document.getElementById("encodedText").value;
> > > > > > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > > > > > for (var z = 0; z < encodedString.length; z++) {
> > > > > > > if (encodedString.charAt(z) == "[") {
> > > > > > > oldlevel=deeplevel;
> > > > > > > deeplevel++;
> > > > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > > > oldlevel=deeplevel;
> > > > > > > deeplevel--;
> > > > > > > stringMem = stringMem.slice(0, -1);
> > > > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > > > > >
> > > > > > > } else {
> > > > > > > stringMem += encodedString.charAt(z);
> > > > > > > }
> > > > > > > }
> > > > > > > }
> > > > > > > </script>
> > > > > > > <body onload="printArray();">
> > > > > > > <form onSubmit="createStruct();">
> > > > > > > <input type="submit" value="INSERT NEW WORDS IN STRUCTURE">
> > > > > > > </form>
> > > > > > > <br>
> > > > > > > <Font size="4">DEBUG</Font><br>
> > > > > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > > > > <br>
> > > > > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > > > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > > > > > <br>
> > > > > > > <Font size="4">STRUCTURE</Font><br>
> > > > > > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > > > > > <br>
> > > > > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > > > > </body>
> > > > > > > </html>
> > > > > >
> > > > > > I can't see how these could do anything wrong, writing to textarea what am i missing?
> > > > > >
> > > > > > document.getElementById("encodedText").value=encodedString;
> > > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > >
> > > > > Changed to button problem fixed.
> > > > >
> > > > > <!DOCTYPE html>
> > > > > <html>
> > > > > <head>
> > > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > > </head>
> > > > > <script>
> > > > > function createStruct() {
> > > > > newword=true;
> > > > > beeninside=false;
> > > > > oldlevel=-1;
> > > > > deeplevel = -1;
> > > > > wordlevel= -1;
> > > > > inserted = false;
> > > > > leftstruct = "[";
> > > > > rightstruct = "]";
> > > > > endstruct = "*";
> > > > > separator = " ";
> > > > > subseparator = "";
> > > > > newString= "";
> > > > > stringPrevMem = "";
> > > > > stringMem = "";
> > > > > posStructString="";
> > > > > //Get values to read in
> > > > > encodedString = document.getElementById("encodedText").value;
> > > > > mystr = document.getElementById("inputTextToSave").value;
> > > > > //Split string into words to read in
> > > > > strArr = mystr.split(separator);
> > > > > //Search words
> > > > > for (var x = 0; x < strArr.length; x++) {
> > > > > newString=strArr[x];
> > > > > stringInserted=false;
> > > > > searchItem(newString);
> > > > > printArray();
> > > > > }
> > > > >
> > > > > alert("closing script");
> > > > > }
> > > > >
> > > > > function searchItem(newString) {
> > > > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > > > while (z < encodedString.length && stringInserted==false) {
> > > > >
> > > > > if (encodedString.charAt(z) == "[") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel++;
> > > > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel--;
> > > > > stringMem = stringMem.slice(0, -1);
> > > > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > //decoded word in memory
> > > > > newword=true; beeninside=false;
> > > > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > > > } else {
> > > > > stringMem += encodedString.charAt(z);
> > > > > newSubString=newString.substring(0,stringMem.length);
> > > > > if (newSubString==stringMem) {
> > > > > oldStructLength=z;
> > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > }
> > > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > > oldStructLength=z;
> > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > newword=false;beeninside=true;
> > > > > stringPrevMem = stringMem;
> > > > > }
> > > > > else if (newSubString<stringMem) {
> > > > > oldStructLength=z;
> > > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > > checkWhatTOInsert();
> > > > > }
> > > > > }
> > > > > z++;
> > > > > }
> > > > > }
> > > > >
> > > > >
> > > > > function checkWhatTOInsert(){
> > > > > putString="";
> > > > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > > > >
> > > > > insertChar = insertString.split('');
> > > > > for (var m=0;m<insertChar.length;m++){
> > > > > putString+="["+insertChar[m];
> > > > > }
> > > > > putString+="*";
> > > > > for (var m=0;m<insertChar.length;m++){
> > > > > putString+="]";
> > > > > }
> > > > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > > > document.getElementById("encodedText").value=encodedString;
> > > > > stringInserted=true;
> > > > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > > > }
> > > > >
> > > > > function insertSubstring(str, index, value) {
> > > > > return str.substr(0, index) + value + str.substr(index);
> > > > > }
> > > > >
> > > > > function printArray() {
> > > > >
> > > > > encodedString = document.getElementById("encodedText").value;
> > > > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > > > for (var z = 0; z < encodedString.length; z++) {
> > > > > if (encodedString.charAt(z) == "[") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel++;
> > > > > } else if (encodedString.charAt(z) == "]") {
> > > > > oldlevel=deeplevel;
> > > > > deeplevel--;
> > > > > stringMem = stringMem.slice(0, -1);
> > > > > } else if (encodedString.charAt(z) == "*") {
> > > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > > > } else {
> > > > > stringMem += encodedString.charAt(z);
> > > > > }
> > > > > }
> > > > > }
> > > > > </script>
> > > > > <body onload="printArray();">
> > > > > <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> > > > > <br>
> > > > > <Font size="4">DEBUG</Font><br>
> > > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > > <br>
> > > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > > > <br>
> > > > > <Font size="4">STRUCTURE</Font><br>
> > > > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > > > <br>
> > > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > > </body>
> > > > > </html>
> > > >
> > > > Pretty close now i just need to position the string/word wordlevel to be inserted on correct deeplevel using paragraphs.
> > > >
> > > > <!DOCTYPE html>
> > > > <html>
> > > > <head>
> > > > <meta http-Equiv="content-type" content="text/html; charset=UTF-8">
> > > > </head>
> > > > <script>
> > > > function createStruct() {
> > > > newword=true;
> > > > beeninside=false;
> > > > oldlevel=-1;
> > > > deeplevel = -1;
> > > > wordlevel= -1;
> > > > inserted = false;
> > > > leftstruct = "[";
> > > > rightstruct = "]";
> > > > endstruct = "*";
> > > > separator = " ";
> > > > subseparator = "";
> > > > newString= "";
> > > > stringPrevMem = "";
> > > > stringMem = "";
> > > > posStructString="";
> > > > //Get values to read in
> > > > encodedString = document.getElementById("encodedText").value;
> > > > mystr = document.getElementById("inputTextToSave").value;
> > > > //Split string into words to read in
> > > > strArr = mystr.split(separator);
> > > > //Search words
> > > > for (var x = 0; x < strArr.length; x++) {
> > > > newString=strArr[x];
> > > > stringInserted=false;
> > > > searchItem(newString);
> > > >
> > > > }
> > > > printArray();
> > > >
> > > > }
> > > >
> > > > function searchItem(newString) {
> > > > oldlevel-1;deeplevel-1;stringPrevMem = "";stringMem = "";z=0;
> > > > while (z < encodedString.length && stringInserted==false) {
> > > >
> > > > if (encodedString.charAt(z) == "[") {
> > > > oldlevel=deeplevel;
> > > > deeplevel++;
> > > > // alert("DBASE Level++ i found _[_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > } else if (encodedString.charAt(z) == "]") {
> > > > oldlevel=deeplevel;
> > > > deeplevel--;
> > > > stringMem = stringMem.slice(0, -1);
> > > > // alert("DBASE Level-- i found _]_ newlevel "+deeplevel+" OldLevel was "+oldlevel+" DBASE string in memory "+stringMem);
> > > > } else if (encodedString.charAt(z) == "*") {
> > > > //decoded word in memory
> > > > newword=true; beeninside=false;
> > > > // alert("DBASE word found _*_ "+deeplevel+" "+oldlevel+" "+stringMem);
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > newSubString=newString.substring(0,stringMem.length);
> > > > if (newSubString==stringMem) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" EQUAL Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > }
> > > > else if (newSubString>stringMem && newword==true && beeninside==false) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" BIGGER Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > newword=false;beeninside=true;
> > > > stringPrevMem = stringMem;
> > > > }
> > > > else if (newSubString<stringMem) {
> > > > oldStructLength=z;
> > > > document.getElementById("debug").value+="Old position="+oldStructLength+" Snaller Newstring="+newSubString+" Stringmem="+stringMem+" Prevstringmem="+stringPrevMem+"\n";
> > > > checkWhatTOInsert();
> > > > }
> > > > }
> > > > z++;
> > > > }
> > > > }
> > > >
> > > >
> > > > function checkWhatTOInsert(){
> > > > putString="";
> > > > if (stringMem.length==stringPrevMem.length){insertString = newString.substring(newSubString.length-1, newString.length);}
> > > > else {insertString = newString.substring(newSubString.length, newString.length);}
> > > >
> > > > insertChar = insertString.split('');
> > > > for (var m=0;m<insertChar.length;m++){
> > > > putString+="["+insertChar[m];
> > > > }
> > > > putString+="*";
> > > > for (var m=0;m<insertChar.length;m++){
> > > > putString+="]";
> > > > }
> > > > encodedString=insertSubstring(encodedString,oldStructLength-1,putString);
> > > > document.getElementById("encodedText").value=encodedString;
> > > > stringInserted=true;
> > > > // alert ("****INSIDE INSERT->"+newSubString+" StringMem "+stringMem+" PrevStringMem "+stringPrevMem);
> > > > }
> > > >
> > > > function insertSubstring(str, index, value) {
> > > > return str.substr(0, index) + value + str.substr(index);
> > > > }
> > > >
> > > > function printArray() {
> > > > document.getElementById("decodedText").value="";
> > > > encodedString = document.getElementById("encodedText").value;
> > > > stringMem="";oldlevel=-1;deeplevel=-1;
> > > > for (var z = 0; z < encodedString.length; z++) {
> > > > if (encodedString.charAt(z) == "[") {
> > > > oldlevel=deeplevel;
> > > > deeplevel++;
> > > > } else if (encodedString.charAt(z) == "]") {
> > > > oldlevel=deeplevel;
> > > > deeplevel--;
> > > > stringMem = stringMem.slice(0, -1);
> > > > } else if (encodedString.charAt(z) == "*") {
> > > > document.getElementById("decodedText").value+=stringMem+"\n";
> > > > } else {
> > > > stringMem += encodedString.charAt(z);
> > > > }
> > > > }
> > > > }
> > > > </script>
> > > > <body onload="printArray();">
> > > > <button onclick="createStruct()">INSERT NEW WORDS IN STRUCTURE</button>
> > > > <br>
> > > > <Font size="4">DEBUG</Font><br>
> > > > <textarea id="debug" cols="80" rows="3"></textarea><br>
> > > > <br>
> > > > <Font size="4">INSERT IN STRUCTURE</Font><br>
> > > > <textarea id="inputTextToSave" cols="80" rows="12">banking bar blouse border</textarea><br>
> > > > <br>
> > > > <Font size="4">STRUCTURE</Font><br>
> > > > <textarea id="encodedText" cols="80" rows="12">[b[a[l[l*]][n[a[n[a*]]]][t*]][u[n*][t[t*]</textarea><br>
> > > > <br>
> > > > <Font size="4">CONTENT READ OUT FROM STRUCTURE</Font><br>
> > > > <textarea id="decodedText" cols="80" rows="12"></textarea><br>
> > > > </body>
> > > > </html>
> > >
> > > The case with words that actually smaller or bigger in array are special cases.
> >
> > http://anybase.co.nf/insert/chessbook.html
> >
> > I think it will work tomorrow and put them correct between paragraphs ...maybe i will use it to create a chessbok where i can read in chessgames in an hieraki and each position gets a probability of win.
> >
> > It is sort of treestructure without restrictions except for memory, it is like treestucture without depth restrictions. And it don't allocate any memory, you really do not keep the full tree in memory just read forward as you search in it. Right now it read the full structure into memory, to insert new string items.
>
> An AI that work on 1KB of memory, doing alot of swapping....
Just looking at the structure one can see that the paragraphs is unnecessary, the left paragraphs is unecessary altogether no need for left object and the right closing ones can be replaced by numbers denoting the level. But it would be cumbersome start the implementation a bit to abstract.
But i think i can start to remove the paragraphs once the program work flawless.
[toc] | [prev] | [next] | [standalone]
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Date | 2017-11-14 14:43 +0000 |
| Message-ID | <141120171443297003%timstreater@greenbee.net> |
| In reply to | #34350 |
In article <f9b44d20-26b5-42a8-8d00-287ed06d81b2@googlegroups.com>, Jonas Thörnvall <jonas.thornvall@gmail.com> wrote: Too long; didn't read. You need to learn how to be more concise. -- "People don't buy Microsoft for quality, they buy it for compatibility with what Bob in accounting bought last year. Trace it back - they buy Microsoft because the IBM Selectric didn't suck much" - P Seebach, afc
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2017-11-14 04:47 -0800 |
| Message-ID | <fa4e6fc6-3582-4a2a-91d3-ed7956126b78@googlegroups.com> |
| In reply to | #34345 |
On Tuesday, November 14, 2017 at 11:34:28 AM UTC+1, Jonas Thörnvall wrote: > why does the script reload after it ended? Which one? You have an onload and an onsubmit... > <form onSubmit="createStruct();"> I am guessing createStruct fails and you get the form submitted. Anyway the code is littered with bugs... Julio
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web