Mirror Text

bherrington0421

Member
Licensed User
Longtime User
Hello!

I'm working on a simple app that will take in text, mirror it, and send it to a printer. My idea for mirroring the text (please suggest another idea if there is an easier way) is to simply load in the a font that is mirrored characters and then reorder the characters of the string in order to complete the mirror. I have been able to change the font of the EditText, but now I want to index through the string (array of characters) so that I can reorder them.

How can I index into a string character by character? Is there an easier way to do this? Keep in mind that I have to be able to print out this mirrored text.

Thanks so much!
 

bherrington0421

Member
Licensed User
Longtime User
Awesome! That is working great for a single line! Thank you so much! Now the issue is that I want people to be able to type in multiple lines of text - so obviously this needs to be mirrored line by line instead of the whole text at once from the EditText. Is there any way to recognize line breaks in side the EditText? Or do I have to split up the entries line by line? Also, is there a way to force a wrap (move to next line) inside an EditText without the text reaching the rightmost border? I would have assumed enter would have worked but it didn't...

Thanks for your time.
 
Upvote 0

bherrington0421

Member
Licensed User
Longtime User
It's close, but see the screenshot I posted. I need it to preserve order for a list or for an entry that is longer than one line. Since it is reversing the entire string and doesn't regard where it wraps to a new line and so it ends up messing with how it should actually look when read back using a mirror. Is there a way to do this with an EditText or do they all need to be separate strings? I could easily substring the entire string from the EditText at a certain character count (stop at a space obviously) and call that a string. Would that be the way to go?

Thanks!
 

Attachments

  • mirrorincorrect.png
    mirrorincorrect.png
    46.8 KB · Views: 289
Upvote 0

bherrington0421

Member
Licensed User
Longtime User
Crlf

There will not always be a CRLF...It won't always be a numbered list like my example and they should also have the option of just entering text and allowing it to wrap.

The ideal would probably be to recognize a CRLF and break there. If there is no CRLF then just enforce a maximum number of characters per line and break at a space before that max is reached. Is it possible to recognize a CRLF inside a string? Thanks for your help.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Yes you can test for CRLF in a string. It seems you need to select a character that will be used to mark the end of a line. It needs to be something they will never use in their text. Something like ~ or maybe ^.

They will need to be instructed to enter this as their end of line marker. The other option you had said before was to make them enter each line in there own edittext and in that case the code you all ready have should work.

Which way will you go??? We need to know that before we write any code.
 
Upvote 0

bherrington0421

Member
Licensed User
Longtime User
Idea

I suppose that way would work. Obviously I would rather not have to do that unless it is the only way to do it...

Couldn't we just loop through the entire string entered via the EditText character by character and on each iteration check to see if the character indicates an CRLF. If there is a CRLF, then substring the string here and restart our count (to count characters for max characters on a line) If there is no CRLF, check to see if we have reached our maximum characters for each line. Once we meet our max character (assuming not every line contains a CRLF), we substring here and reset count. We do this through the whole string and then we would be left with strings that represent each line in our entry.

Am I missing something or would this work?
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
I think this will do what you want. Run this sample and see how it works. If you have any issues changing it for your edittext let me know.

B4X:
Sub Split_Test
   'you will replace mytext with your edittext.text values or do: mytext = Youredittext.text first
   Dim mytext, answers() As String 
   mytext = "This is a test to see" & CRLF & "how the new split and" & CRLF & "mirror functions will work"
   answers = Split_GetSentences(mytext, CRLF)
   Dim newlines(answers.Length) As String
   For l = 0 To answers.Length -1
      Msgbox(Mirror(answers(l)), "Show Reversed Text")
   Next
End Sub
Sub Split_GetSentences(Text As String, Split_At As String) As String()
   Dim Lines() As String
   Lines = Regex.Split(Split_At, Text)
   Return Lines
End Sub
Sub Mirror(Text As String) As String
   Dim ns As String : ns = ""
   For l = Text.Length -1 To 0 Step -1
      ns = ns & Text.SubString2(l, l+1)
   Next
   Return ns
End Sub
 
Upvote 0

bherrington0421

Member
Licensed User
Longtime User
That's closer, its splitting up the lines when there is a manually entered CRLF perfectly, but not it runs all the way the to end of the line. We need to recognize this to preserve the order or otherwise (see screenshot) things get flipped around and the beginning of the reminder ends up at the bottom...

The first character of the first line should be the last character of the same line after it is reversed. Right now it is taking the whole chunk until there is a CRLF, and so if the chunk of text is longer than a line, than that last character gets forced down onto the second line. We need to break these up somehow to ensure that this doesn't occur. Your technique is working great for single line entries with a manual CRLF. But if that entry runs onto a second line, the first character of the entry gets pushed down because we are flipping it all at once. The screen shot demonstrates this. Instead of what it is doing now, it should look like this:

regonl si taht tset a si siHT .1
.enil eno nath

Thanks again for all your help.
 
Upvote 0
Top