Sub MarkPattern(Input As String, Pattern As String, GroupNumber As Int) As String
Dim sb As StringBuilder
Dim lastMatchEnd As Int = 0
Dim m As Matcher = Regex.Matcher(Pattern, Input)
sb.Initialize
Do While m.Find
Dim currentStart As Int = m.GetStart(GroupNumber)
Dim SmileCode As String
Dim SmileCodeToimage As String
SmileCode = m.Group(GroupNumber)
SmileCodeToimage = CreateSmileyImage(0, 0, DipToCurrent(30), DipToCurrent(30), SmileCode&".gif")
sb.Append(Input.SubString2(lastMatchEnd, currentStart) & SmileCodeToimage)
lastMatchEnd = m.GetEnd(GroupNumber)
Loop
If lastMatchEnd < Input.Length Then
sb.Append(Input.SubString(lastMatchEnd))
End If
Return sb.ToString
End Sub
simply i have a string just looks like that
" hello -) how is everything -) "
but the output comes backword "-) everything is how -)"
It was a mistyped since i wrote the results forget to include it, the thing is the whole string printed backwardsI don't have time to look at this right now, but at first glance:
what happened to the "hello" in the source string?
It doesn't look like the output is backwards, it looks more like it has just lopped off the leading "hello".
i know that i can simply use string.replace but that is not the case that i aim for
The string builder should remove the smile operator and place the generated SMM String but i have no idea why the final results printed out backwards
Sub AppStart (Args() As String)
Dim SmileyPattern as string = "\-\)" 'is actually "-)" after escaping non-alphanumeric regex characters
Dim TestInput As String = " hello -) how is everything -) "
Dim TestOutput As String = MarkPattern(TestInput, SmileyPattern, 0)
Log("Input string = """ & TestInput & """")
Log("Output string = """ & TestOutput & """")
End Sub
Sub MarkPattern(Input As String, Pattern As String, GroupNumber As Int) As String
Dim sb As StringBuilder
Dim lastMatchEnd As Int = 0
Dim m As Matcher = Regex.Matcher(Pattern, Input)
sb.Initialize
Do While m.Find
Dim currentStart As Int = m.GetStart(GroupNumber)
Dim SmileCode As String
Dim SmileCodeToimage As String
SmileCode = m.Group(GroupNumber)
SmileCodeToimage = "[[SMILEY CODE]]" '''CreateSmileyImage(0, 0, DipToCurrent(30), DipToCurrent(30), SmileCode&".gif")
sb.Append(Input.SubString2(lastMatchEnd, currentStart) & SmileCodeToimage)
lastMatchEnd = m.GetEnd(GroupNumber)
Loop
If lastMatchEnd < Input.Length Then
sb.Append(Input.SubString(lastMatchEnd))
End If
Return sb.ToString
End Sub
Waiting for debugger to connect...
Program started.
Input string = " hello -) how is everything -) "
Output string = " hello [[SMILEY CODE]] how is everything [[SMILEY CODE]] "
You are correct when BBCodeView Right to Left Property is set to true the text printed out backward thats very weird the behavior shouldn't happened.In the words that programmers love: it seems to be working ok here ?
Perhaps it's a northern-hemisphere vs southern-hemisphere thing, similar to: which way does water spin into drain hole.
Or... are you using a right-to-left language? Unicode does some interesting stuff in those cases, especially if the text also includes left-to-right numbers.
B4X:Sub AppStart (Args() As String) Dim SmileyPattern as string = "\-\)" 'is actually "-)" after escaping non-alphanumeric regex characters Dim TestInput As String = " hello -) how is everything -) " Dim TestOutput As String = MarkPattern(TestInput, SmileyPattern, 0) Log("Input string = """ & TestInput & """") Log("Output string = """ & TestOutput & """") End Sub Sub MarkPattern(Input As String, Pattern As String, GroupNumber As Int) As String Dim sb As StringBuilder Dim lastMatchEnd As Int = 0 Dim m As Matcher = Regex.Matcher(Pattern, Input) sb.Initialize Do While m.Find Dim currentStart As Int = m.GetStart(GroupNumber) Dim SmileCode As String Dim SmileCodeToimage As String SmileCode = m.Group(GroupNumber) SmileCodeToimage = "[[SMILEY CODE]]" '''CreateSmileyImage(0, 0, DipToCurrent(30), DipToCurrent(30), SmileCode&".gif") sb.Append(Input.SubString2(lastMatchEnd, currentStart) & SmileCodeToimage) lastMatchEnd = m.GetEnd(GroupNumber) Loop If lastMatchEnd < Input.Length Then sb.Append(Input.SubString(lastMatchEnd)) End If Return sb.ToString End Sub
Log file output:Waiting for debugger to connect... Program started. Input string = " hello -) how is everything -) " Output string = " hello [[SMILEY CODE]] how is everything [[SMILEY CODE]] "
ps congrats on your code retaining the leading and trailing spaces; many first-draft string de/re-construction algorithms would have lost one or both of them ?
Sub MarkPattern(Input As String, Pattern As String, GroupNumber As Int) As String
Dim sb As StringBuilder
Dim lastMatchEnd As Int = 0
Dim m As Matcher = Regex.Matcher(Pattern, Input)
sb.Initialize
Do While m.Find
Dim currentStart As Int = m.GetStart(GroupNumber)
Dim SmileCode As String
Dim SmileCodeToimage As String
SmileCode = m.Group(GroupNumber)
SmileCodeToimage = SetSmiley(0, 0, DipToCurrent(30), DipToCurrent(30),SmileCode&".gif")
sb.Append(Input.SubString2(lastMatchEnd, currentStart)) ' this will shows normally in BBCodeview
lastMatchEnd = m.GetEnd(GroupNumber)
Loop
If lastMatchEnd < Input.Length Then
sb.Append(Input.SubString(lastMatchEnd))
End If
Return sb.ToString
End Sub
Sub MarkPattern(Input As String, Pattern As String, GroupNumber As Int) As String
Dim sb As StringBuilder
Dim lastMatchEnd As Int = 0
Dim m As Matcher = Regex.Matcher(Pattern, Input)
sb.Initialize
Do While m.Find
Dim currentStart As Int = m.GetStart(GroupNumber)
Dim SmileCode As String
Dim SmileCodeToimage As String
SmileCode = m.Group(GroupNumber)
SmileCodeToimage = SetSmiley(0, 0, DipToCurrent(30), DipToCurrent(30),SmileCode&".gif")
sb.Append(Input.SubString2(lastMatchEnd, currentStart) & SmileCodeToimage) ' substring the smilecode and add SmileCodeToimage
lastMatchEnd = m.GetEnd(GroupNumber)
Loop
If lastMatchEnd < Input.Length Then
sb.Append(Input.SubString(lastMatchEnd))
End If
Return sb.ToString
End Sub
simply i have a string just looks like that
" hello -) how is everything -) "
but the output comes backword "-) everything is how -) hello"
but this will add the image instead of the SmileCode but it will be showing backwarded in BBcodeView which i dont know why this has been caused and how to fix it
Waiting for debugger to connect...
Program started.
Input string = " hello -) how is everything -) "
Output string = " hello [[SMILEY CODE]] how is everything [[SMILEY CODE]] "
The BBCodeView with the property of RTL enabled. In the beginning i was doubt that iam doing something wrong in the makepattern function. But at the end its BBCodeView related thing if RTL property enabled which something not related to the whole codeLol I am so confused now, but perhaps I misunderstood the problem.
Which of these is backward? :
- the string returned by MarkPattern()
- the on-screen display of that string by BBcodeView
The log file output of post #6 indicates that MarkPattern() is not causing the backwardness (with two smileys, at least) :
Log file output:Waiting for debugger to connect... Program started. Input string = " hello -) how is everything -) " Output string = " hello [[SMILEY CODE]] how is everything [[SMILEY CODE]] "
The BBCodeView with the property of RTL enabled
I have searched about BBCodeView RTL and found only one post that asks for RTL feature. I will use BBCodeView to view text messages and for sure i had to enable RTL for multilingual supportInteresting. Are you actually working with a RTL language eg Arabic, Hebrew, Kurdish ?
I remember some strange goings-on a couple of years back to do with Hebrew language and... I think it was zero-width-joiners being used to superimpose some characters to make up a currency symbol. Hang on a min while I test out the forum search feature.
I remember some strange goings-on a couple of years back to do with Hebrew language and... I think it was zero-width-joiners being used to superimpose some characters to make up a currency symbol.
then: what happens if you disable RTL?I will use BBCodeView to view text messages and for sure i had to enable RTL for multilingual support
the log output is- the BBCodeView displayed output for that string?
Screenshot attached.Could you show a screen dump of
- the " hello -) how is everything -) " string being passed into MarkPattern(), and
if RTL property is set to False in BBcodeview the text printed out correctly , but this wont help since arabic,kurdish,hebrew language are supported in my app.Also, I'm still not certain on: are you actually working with a RTL language eg Arabic, Hebrew, Kurdish ?
And if you've got BBCodeView in RTL mode per:
then: what happens if you disable RTL?
if RTL property is set to False in BBcodeview the text printed out correctly , but this wont help since arabic,kurdish,hebrew language are supported in my app.
No dude RTL are always enabled during BBCodeView initialization, since those messages in the chat room should be showing correctly from each user. Its not based on user devicesI'm thinking your app set the BBCodeView RTL property to True only if your app (or the phone locale?) is using a RTL language.
With luck this is something that you need do only when a layout is loaded.
' by default we will set RTL to /false
BBCodeView1.RTL = False
' this is an ugly way to detect if input string is english or arabic or hebrew if so set rtl to true
If TextInput.ToLowerCase = TextInput.ToUpperCase Then
BBCodeView1.RTL = True
End If
Hello [View=view0/] how is everything [View=view1/]
an ugly workaround can be something Like this
B4X:If TextInput.ToLowerCase = TextInput.ToUpperCase Then
Sub CheckRTL(inputText As String) As Boolean
Dim matcher1 As Matcher
' check code range for {hebrew,arabic,persain,Chinese}...
matcher1 = Regex.Matcher("[\u0591-\u07FF-\u4E00-\u9FA5]", inputText)
Dim strfound As Boolean = matcher1.Find
Return strfound
End Sub
dim rtlstr as String = "זזه الا"
If CheckRTL(rtlstr)Then
BBCodeView1.RTL = True
End If
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?