But, it was real one for me.
And, Solved somewhat like this.
I know it is not the best (good) but, it is my best
And, If possible, I would like to know some more nicer approach.
< Situation >
-A sentence is given.
-I have to split it several lines, in this sample code the line count is "5"
-when you split it, you have to do your best to keep it even length for each line
-while split, keep a word not broken, and the first character should not a space
Given sentence is;
"The Open Web Application Security Project(OWASP) provides a very good list of the Top 10 web application security flaws, including an summary of the nature, severity and impact of each."
And my records goes;
First try
-simply character by character
-exactly 37 characters each line
-its arrangement is the best though
-it looks like silly, it splits whole word, and space showed at the first of line
Code: Select all
; the first number is character counts of its line, the 2nd number is counts of words
;37, 6 The Open Web Application Security Pro
;37, 6 ject(OWASP) provides a very good list
;37, 7 of the Top 10 web application securi
;37, 7 ty flaws, including an summary of the
;37, 6 nature, severity and impact of each.
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
characterBasedSentenceArrangement(문장, 줄수)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{
StringSplit, 글자, 문장
전체글자수 := StrLen( 문장)
줄당글자수 := Floor( 전체글자수/줄수)
잔여글자수 := Mod( 전체글자수, 줄당글자수)
문장재구성 := Array()
Loop % 줄수
{
글자한개추가 := 0
If ( A_Index <= 잔여글자수)
글자한개추가 := 1
이번줄내용 := ""
Loop % 줄당글자수 + 글자한개추가
{
색인 ++
이번줄내용 .= 글자%색인%
}
문장재구성.Insert( 이번줄내용 )
}
For Each, 한줄내용 in 문장재구성
{
RegExReplace( RegExReplace( 한줄내용, "\s+", " "), "\S+", "", 한줄단어수 )
결과 .= StrLen( 한줄내용) ", " 한줄단어수 " " 한줄내용 "`n"
}
StringTrimRight, 결과, 결과, 1
Return 결과
}
-word by word
-exactly 6 words each line
-arrangement is worst, because each words has its own length
-no broken words at all
Code: Select all
;49, 6 The Open Web Application Security Project(OWASP)
;29, 6 provides a very good list of
;36, 6 the Top 10 web application security
;35, 6 flaws, including an summary of the
;37, 6 nature, severity and impact of each.
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wordBasedSentenceArrangement(문장, 줄수)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{
StringSplit, 단어, 문장, % A_Space
전체단어수 := 단어0
줄당단어수 := 전체단어수//줄수
잔여단어수 := Mod( 전체단어수, 줄당단어수)
문장재구성 := Array()
Loop % 줄수
{
단어한개추가 := 0
If ( A_Index <= 잔여단어수)
단어한개추가 := 1
이번줄내용 := ""
Loop % 줄당단어수 + 단어한개추가
{
색인 ++
이번줄내용 .= 단어%색인% " "
}
문장재구성.Insert( 이번줄내용 )
}
For Each, 한줄 in 문장재구성
{
RegExReplace( RegExReplace( 한줄, "\s+", " "), "\S+", "", 한줄단어수 )
결과 .= StrLen( 한줄) ", " 한줄단어수 " " 한줄 "`n"
}
StringTrimRight, 결과, 결과, 1
Return 결과
}
-modification of the first
-it is my best
Code: Select all
;34, 5 The Open Web Application Security
;41, 6 Project(OWASP) provides a very good list
;39, 7 of the Top 10 web application security
;35, 6 flaws, including an summary of the
;36, 6 nature, severity and impact of each.
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
characterBasedSentenceArrangementModified(문장, 줄수)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{
StringSplit, 글자, 문장
쪽집게 := Array()
Loop % 글자0
{
StringLeft, 좌측전체, 문장, % A_Index
StringTrimLeft, 우측전체, 문장 , % A_Index
단어전반 := RegExReplace( 좌측전체, ".*?([^ ]*)$", "${1}")
단어후반 := RegExReplace( 우측전체, "^([^ ]*).*", "${1}")
쪽집게.Insert([단어전반, 단어후반])
}
전체글자수 := StrLen( 문장)
줄당글자수 := Floor( 전체글자수/줄수)
잔여글자수 := Mod( 전체글자수, 줄당글자수)
문장재구성 := Array()
색인 := 1
Loop % 줄수
{
글자한개추가 := 0
If ( A_Index <= 잔여글자수)
글자한개추가 := 1
이번줄글자개수 := 줄당글자수 + 글자한개추가
이번줄맨끝색인 := 색인 + 이번줄글자개수
If ( A_Index - 1 < 줄수 )
{
맨끝단어전반길이 := StrLen( 쪽집게[이번줄맨끝색인][1])
맨끝단어후반길이 := StrLen( 쪽집게[이번줄맨끝색인][2])
If ( 맨끝단어전반길이 < 맨끝단어후반길이)
이번줄글자개수 := 이번줄글자개수 - 맨끝단어전반길이
Else
이번줄글자개수 := 이번줄글자개수 + 맨끝단어후반길이 + 1
}
Else
이번줄글자개수 := 전체글자카운트 - 전체글자색인
이번줄내용 := ""
Loop % 이번줄글자개수 + 1
{
이번줄내용 .= 글자%색인%
색인 ++
}
문장재구성.Insert( 이번줄내용)
}
For Each, 한줄 in 문장재구성
{
RegExReplace( RegExReplace( 한줄, "\s+", " "), "\S+", "", 한줄단어수 )
결과 .= StrLen( 한줄) ", " 한줄단어수 " " 한줄 "`n"
}
StringTrimRight, 결과, 결과, 1
Return 결과
}
Thanks
[EDIT]
Ah.... I just figured out, for the last line of them.
Its condition is very simple.
If it has at least one word(including last dot) that is fine enough.
So, the solutions could be some.. easier or more difficult ? I do not know...