By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

convert just superscript format of rtf to html <sup>

100+
P: 228
I am having headache with this one. I have a single rtf ctrl that have a button next to it to make a superscript. That is needed cos the program deals with a local language that needs superscript for explanation purpose. As we are feeding data using a GUI and rtf control seems to do the job,I am going ahead with it.

Now the problem is I cant replace the superscript rtf to html. I tried till this stage:

Expand|Select|Wrap|Line Numbers
  1.  Dim k As String = (TextBox1.Rtf)
  2.         Dim intfs17 As Integer = InStr(k, "\fs17", CompareMethod.Text)
  3. 'fs17 is the last string in the rtf header i blv
  4.         If intfs17 > 0 Then
  5.             'replace till it now. erase till it all.
  6.             Dim b As New StringBuilder
  7.             b.Append(k)
  8.             b.Remove(0, intfs17 + 4) 'removes all the stuff from first char to the word intfs17
  9.             b.Replace("\par", "") 
  10.             b.Replace("}", "")
  11.             b.Replace("\up4", "") 'non superscripts or ordinary words
  12.             '****************************
  13. 'NOw here I remain with a string that contains words with superscript format. E.g. html wise <sup>a</sup>bc
  14. and in rtf wise it is a\up0 bc
  15.  
  16. 'I thot of the following line but it is obviously going to hog the program very much
  17.             k = b.ToString
  18.             Dim i As Integer = 0
  19.             Dim c As Integer = 0
  20.             For i = k.Length - 1 To 0
  21.                 If k.Substring(i, 4) = "\up0" Then 'we ve a super script
  22.             c = i + 4
  23. 'stuck!
  24.  
  25.                 End If        
  26.             Next
  27.  
  28.         End If
  29.  
Now my questions are 2:

1. How can I replace \up0 with the right html superscripting?

2. for each char superscripted, rtf separates using a single space. How would i differ that from spaces i am going to use to separate the entered words?

Any any help is greatly appreciated!
Dec 17 '14 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,033
You should not loop through the string, use InSrt instead.

Expand|Select|Wrap|Line Numbers
  1. Dim s as String ="abcde"
  2. Dim i as Integer
  3. a=Instr(s,"d",1)
  4.  
now a has the value 4.
Dec 18 '14 #2

100+
P: 228
Am sure there is a better way to do this but since i am in a hurry, i did finish it this way. It wont work if first alpahebt is superscriptted but that is not the case in my form so it is ok...

Expand|Select|Wrap|Line Numbers
  1.    Private Function supSub(ByVal inthowmuch As Integer) As String
  2.         'returns final html'ed word
  3.         Dim strr As String = ""
  4.         TextBox1.SelectionCharOffset = inthowmuch
  5.         TextBox1.SelectedText = TextBox1.SelectedText
  6.         TextBox1.SelectionCharOffset = 0
  7.         Dim k As String = (TextBox1.Rtf)
  8.         Dim intfs17 As Integer = InStr(k, "\fs17", CompareMethod.Text)
  9.         If intfs17 > 0 Then
  10.             'replace till it now. erase till it all.
  11.             Dim b As New StringBuilder
  12.             b.Append(k)
  13.             b.Remove(0, intfs17 + 4)
  14.             b.Replace("\par", "")
  15.             b.Replace("}", "")
  16.             b.Replace("\up4", "") 'non pe
  17.             'see if we ve superscripts within the scriptsb.
  18.             k = b.ToString
  19.             k = Trim(k)
  20.             Dim i As Integer = 0
  21.             Dim c As Integer = 0
  22.             Dim p As String()
  23.             p = k.Split(" ")
  24.  
  25.  
  26.             Dim r As New Dictionary(Of Integer, Integer)
  27.             r.Clear()
  28.             For i = 0 To p.Count - 1
  29.                 If p(i).EndsWith("\up0") = True Then
  30.                     p(i) = "<sup>" & p(i).Replace("\up0", "</sup>")
  31.                     If p(i + 1).EndsWith("\up0") = False Then
  32.                         p(i) = p(i) & p(i + 1)
  33.                         r.Add(i + 1, i + 1)
  34.                     End If
  35.                     If p(i - 1).EndsWith("\up0") = False Then
  36.                         p(i) = p(i - 1) & p(i)
  37.                         r.Add(i - 1, i - 1)
  38.                     End If
  39.  
  40.                 End If
  41.             Next
  42.  
  43.             strr = ""
  44.             For i = 0 To p.Count - 1
  45.                 If r.ContainsKey(i) = False Then
  46.                     strr = strr & p(i) & " "
  47.                 End If
  48.  
  49.             Next
  50.  
  51.         End If
  52.  
  53.  
  54.         Return strr
  55.     End Function
  56.  
Dec 18 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.