|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I want to reverse text. Basically the text is in hebrew and the best way for me to display it is to switch each word within a sentence around doing sentence at a time.
For example asp is fun to program in would be psa si nuf ot margorp. I'm not sure where to start. Any suggestions in how to do this? |
|
#2
|
|||
|
|||
|
strReverse
the function strReverse reverses a string.
You can program the following: Split the string into an array with space as delimiter, For..Next through the array and use strReverse on each array element, and Join the array with space as delimiter. Code:
strTest = "asp is fun to program" aString = Split(strTest, " ") For i = 0 To Ubound(aString) aString(i) = strReverse(aString(i)) Next strTest = Join(aString, " ")
__________________
- Rogier Doekes |
|
#3
|
|||
|
|||
|
Thanks,
How would i add to do line by line at a time between each <p></p> or <p align=xxx> and</p> not including the paragraph marks Esther |
|
#4
|
|||
|
|||
|
actually in addition to above also
I need it to be between ascii 224 and 251 so thatit doesn't reverse english or html. Can you help me with any of these steps? Esther |
|
#5
|
|||
|
|||
|
Well Esther,
I tried my best to whip up some code. Be sure to test the code, since I loosely tested it, and I am not able to read hebrew on my browser. Code:
<% Option Explicit
'dump the whole text in a variable
'search in the variable for <p and > and </p> (InStr)
'Split the in between text delimiter space
'Loop through the split array and search for ASC 224 - ASC 251
'If there are characters in that array element, reverse
'Join Array and add to the output variable
Dim strInput 'input string
Dim strOut 'output string
Dim aPar, i, j 'word split and indexes for loops
Dim intCurrentPosition 'where are we in the text
Dim intParTag, intParTagLength 'what position starts the <p> tag and how long
Dim intParCloseBracket 'what position ends the <p> tag
Dim intParEndTag 'what position start the </p> tag
Dim bNeedReversal 'flag to determine whether reversal is needed or not
'your input string
strInput = ""
'initialize output string
strOut = ""
'start at the beginning of the text file
intCurrentPosition = 1
'loop thru the text file
Do While Not intCurrentPosition > Len(strInput)
'position of the paragaph tag
intParTag = inStr(intCurrentPosition, strInput, "<p", 1)
If intParTag > 0 Then 'found a pararagh tag
'end position of the paragraph tag (<p> is smaller then <p align="left"> ;))
intParCloseBracket = inStr(intParTag, strInput, ">", 1)
'start position of the end paragraph tag
IntParEndTag = inStr(intParCloseBracket, strInput, "</p>", 1)
Else 'did not found a par tag
intParEndTag = 0
End If
If intParTag = 0 Or intParEndTag = 0 Then 'exit routine to grab the remaining document
strOut = strOut & Mid(strInput, intCurrentPosition + 1, Len(strInput) - (intCurrentPosition -1))
Exit Do
ElseIf intCurrentPosition = 1 Then 'grab the beginning of the document
strOut = strOut & Mid(strInput, intCurrentPosition, intParTag - 1)
End If
'add paragraph tag
intParTagLength = IntParCloseBracket - (intParTag - 1) 'how long is the tag?
strOut = strOut & Mid(strInput, intParTag, intParTagLength)
'split the paragraph text into words
aPar = Split(Mid(strInput, intParCloseBracket + 1, (intParEndTag - 1) - intParCloseBracket), " ")
'loop thru words
For i = 0 To Ubound(aPar)
'do we need to reverse flag
bNeedReversal = True
For j = 1 To Len(aPar(i)) 'loop thru characters of each word
If Asc(Mid(aPar(i), j, 1)) < 224 Or Asc(Mid(aPar(i), j, 1)) > 251 Then
'english characters or HTML characters
bNeedReversal = False
Exit For
End If 'asc test
Next 'j
'reverse word only when reversal flag is set
If bNeedReversal Then aPar(i) = strReverse(aPar(i))
Next 'i
'paste all the words back together
strOut = strOut & Join(aPar, " ")
'add end paragrap tag
strOut = strOut & mid(strInput, intParEndtag, 4)
'move the currentposition up to new paragraph
intCurrentPosition = intParEndTag + 3
Loop
Response.Write strOut 'display final result
%>
Hope this helps, |
|
#6
|
|||
|
|||
|
wow thanks!
I'm going to try this out. It looks good!!! Thanks for the help. Esther |
|
#7
|
|||
|
|||
|
I've been playing with your above code. thanks for the help.
Would you know how to switch the direction of the sentence to right to left also. (Also only if it's within the ascii code that I specified) Thanks, Esther |
|
#8
|
|||
|
|||
|
The default text direction setting is "ltr" (left to right), you will need it to be "rtl" (right to left) for the hebrew text.
If the hebrew text takes up whole paragraphs seperate from any english text, you could use <p dir="rtl">. If it applies to a whole table cell then <td dir="rtl"> or an entire table then <table dir="rtl">. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > reversing text |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|