![]() |
|
||||||||||
|
|||||
|
Регистрация: Feb 2010
Сообщений: 102
|
Есть String в которой занесены какие то данные.
Надо написать цикл который будет делать перенос на следующую строку через каждые 80 символов. Как это сделать? |
|
|||||
|
Регистрация: Jan 2010
Адрес: владивосток
Сообщений: 250
|
|
|
|||||
|
Регистрация: Feb 2010
Сообщений: 102
|
var stroka:String=new String(); stroka="Woke up and I feel like shit I don't remember last night, I'm getting sick of this I hit the bottle when I got off stage And got piss drunk stupid and went in a rage I think I mighta got into a fight Because my knuckles were bloody and I don't feel alright I hit the bottom and I don't even care Some say I'm going to hell but I'm already there Sick and tired of being sick and tired"; for(var i:int = 0; i = 80, i = 160; i ++) { var st:String="<tr>"+stroka; } |
|
|||||
|
Регистрация: Jan 2010
Адрес: владивосток
Сообщений: 250
|
ой , я ошибочку допустил , i = 80 && i =160
|
|
|||||
|
Регистрация: Feb 2010
Сообщений: 102
|
ну как бы не совсем понятен принцип ... во первых там никак не может быть i = 80 && i =160 ибо в цикле одна и та же переменная в одном и том же шаге не может быть равна разным числам, ну по крайней мере в данном случае ... во вторых там должен бытиь знак равенства ... но опять же не совсем понятно как всё таки правильно организовать цикл.
|
|
|||||
|
Modus ponens
|
__________________
Hell is the possibility of sanity |
|
|||||
var str:String = "Woke up and I feel like shit I don't remember last night, I'm getting sick of this I hit the bottle when I got off stage And got piss drunk stupid and went in a rage I think I mighta got into a fight Because my knuckles were bloody and I don't feel alright I hit the bottom and I don't even care Some say I'm going to hell but I'm already there Sick and tired of being sick and tired"; var strResult:String = ''; var strTransfer:int = 80; for (var i:int = 0; i < str.length; i ++) { strResult = strResult + str.charAt(i); if ((i % strTransfer == 0) && (i != 0)) { strResult = strResult + '\n'; trace(i); //80, 160, 240, 320 ... } } trace(strResult); // Строки по 80 символов. Сорри, мой вариант будет медленнее ![]()
__________________
круглое тащим, квадратное катим |
|
|||||
|
Et cetera
Регистрация: Sep 2002
Сообщений: 30,787
|
var str:String = "Woke up and I feel like shit I don't remember last night, I'm getting sick of this I hit the bottle when I got off stage And got piss drunk stupid and went in a rage I think I mighta got into a fight Because my knuckles were bloody and I don't feel alright I hit the bottom and I don't even care Some say I'm going to hell but I'm already there Sick and tired of being sick and tired"; var r:RegExp = /(.{20})/g; str = str.replace(r, '$1\n'); trace(str); ![]() |
|
|||||
|
Регистрация: Feb 2010
Сообщений: 102
|
спасибо)
|
|
|||||
|
Modus ponens
|
Цитата:
![]()
__________________
Hell is the possibility of sanity |
![]() |
![]() |
Часовой пояс GMT +4, время: 13:24. |
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | |
| Опции просмотра | |
|
|