Jump to content

Text Lengh, JS

- - - - -

  • Please log in to reply
11 replies to this topic

#1
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
I have text in table or div.
I have some problem. If i Write large text in table without spaces, table (or div) width will increase.

For example:
<table width="70px" border="1">

<tr> <td>HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE </td></tr>

</tabl>

I want to write a code in javascript, that will writes \n if the string length is, for instance, 300 Symbols. Or something script like this. For example, If someone add the large text in my web page, page will be stretched. OR if i have chat System in may web page.


I make the same in C, But unfortunately I don't know JS.


#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

main(){     

int k=0, i=1, p;

printf("Enter Size Of String In Number:");

scanf("%d", &p);   

  char c; 

  freopen("dat.txt", "r", stdin); 

  freopen("dat2.txt", "w", stdout); 

do

 {        

   c=getchar();  

   if (c=='\n' || c=='\t' || c=='\b' || c=='\f' || c=='\r' ) continue;  

   if(k==p*i){ printf ("\n");  i++; }        

   printf("%c", c);  k++;  

 }while(c!=EOF);


printf("\n\n|......%d Symbols in One String......|", p); 

getch();  

}





Posted Image

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Does it have to be with javascript because it's some kind of assignment or does the number of characters / row really matter ( i is much smaller than B)?

If not you can do:
<table width="70px" border="1" [B][COLOR="red"]style="word-break: break-all;"[/COLOR][/B]>


#3
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
You are right. Symbol "@" is bigger than "i". So i don't know what do do.

this does not works.
<html>
<body>
<table width="70px" border="1" style="word-break:break-all;">
<tr> <td>HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE </td></tr>
</table>  
</body>
</html>


#4
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Or i need something like this. If (string length>="70px) ===> \n

#5
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Okay i see.. It doesn't seem to work in FF.
Well this certainly works:

var table = document.getElementById("myTable");

			

for (var i = 0; i<table.rows.length; i++) {

	for(var j=0 ; j<table.rows[i].cells.length ; j++){

		var td = table.rows[i].cells[j];

		var content = td.innerHTML;

		var newContent ="";

		

                for(var k=0 ; k<content.length-1 ; k++){					

			newContent += content.substring(k, k+1) + "<wbr>";

		}

		td.innerHTML = newContent;

	}

}

It basicly puts a "<wbr>" behind every character.

If you don't know what <wbr> is (wordbreak):
It tells the browser you can put a wordbreak here (newline pretty much) if you want to. If it's not needed, leave it.

#6
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
All the simbols in one font have the same lengh.
the lengh of "i" and the lengh of "A" is same. We could test thiis.

see this:

123456789 <<=== 9 symbol;
iiiiiiiii <<=== 9 symbol; the lengh is same;
AAAAAAAAA <<=== 9 symbol; the lengh is same;
QQQQQQQQQ <<=== 9 symbol; the lengh is same;


But problems are in other language fonts. For instance, in my language fonts.
"o" is "ო" in my language. and lengh of "o" is bigger than "o"

ooooo <<<<==== 5
ააააა <<<<==== 5
ოოოოო <<<<==== 5

what can i do? My Algorithm, that i write in C , will not work with my language fonts.

In addition, IF you are in Windows and if you wont to see my Language fonts, you
should go to CONTROL PANEL>>> REGIONAL AND LANGUGE> LANGUAGES> INSTALL FILES FOR COMPLEC SCRIPTS



wim DC
thanks. I will think for your code.

#7
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
style="word-break:break-all;  
thats good way but only IE works width this code.

#8
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
You must replace your current Georgian font with a monospace fixedwidth Georgian font if it does exist. Courier or courier new do not support most fixed-width non-latin characters.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#9
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Nullw0rm
I will convert the characters and than I'll Use JS Script like my program In C. Will not i?


Also this say is a very good. but This works only In IE. I want to know .... why? its very bad that Browsers have a problems With HTML CSS. sometimes each browser open pages different...

#10
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
wim DC

Also that works only in IE. why have JS so many problems width Browsers? :(





<html>

<head>

</head>


<script type="text/javascript">


var table = document.getElementById("myTable");

			

for (var i = 0; i<table.rows.length; i++) {

	for(var j=0 ; j<table.rows[i].cells.length ; j++){

		var td = table.rows[i].cells[j];

		var content = td.innerHTML;

		var newContent ="";

		

                for(var k=0 ; k<content.length-1 ; k++){					

			newContent += content.substring(k, k+1) + "<wbr>";

		}

		td.innerHTML = newContent;

	}

}



</script>


<body onload="DoSplitStringForAllTd()">

<table style="WORD-BREAK:BREAK-ALL" width="300px" border="1"> 

<tr> <td>HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAA</td></tr> 

</table>

</body>

</html>




#11
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

VakhoQ said:

wim DC

Also that works only in IE. why have JS so many problems width Browsers? :(





<html>

<head>

</head>


<script type="text/javascript">


var table = document.getElementById("myTable");

			

for (var i = 0; i<table.rows.length; i++) {

	for(var j=0 ; j<table.rows[i].cells.length ; j++){

		var td = table.rows[i].cells[j];

		var content = td.innerHTML;

		var newContent ="";

		

                for(var k=0 ; k<content.length-1 ; k++){					

			newContent += content.substring(k, k+1) + "<wbr>";

		}

		td.innerHTML = newContent;

	}

}



</script>


<body onload="DoSplitStringForAllTd()">

<table style="WORD-BREAK:BREAK-ALL" width="300px" border="1"> 

<tr> <td>HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAA</td></tr> 

</table>

</body>

</html>



It does work here with chrome, IE and FF. For FF you just need to put it in a function and call it from the body onload="".

#12
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
thanks a lot.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users