473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

convert just superscript format of rtf to html <sup>

228 100+
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
2 1693
Luuk
1,047 Expert 1GB
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
samvb
228 100+
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

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

Similar topics

1
by: dan | last post by:
Im sure this has been asked a million times, but Im I couldn't find it. So, why not make it 1 million +1. I am looking for the best way to format html, to be put into a INSERT statement. The...
2
by: Rock | last post by:
Hi,all: how to convert VBA #date# format (ex: #2004/3/6#) to C# code ? here are vba code : Dim objUserPerm As Office.UserPermission Set objUserPerm =...
1
by: solomon_13000 | last post by:
How do I actually convert different video format (avi,mpeg,mp4, etc) file to a flash format and view it as flash? People would upload their video files on my server and my server will do the...
5
nirmalsingh
by: nirmalsingh | last post by:
i am getting date format in string as 30-11-2006 05:59:44 PM . i want to convert in the format of yyyy-mm-dd hh:mm:ss to sore it in mysql database. Help me with sample coding plz..
0
by: VinDiesal | last post by:
Hi Buddies, I want the Sample source code about How to convert Dss audio format to wav format in .net. Please anybody send the source code for this.
3
by: Academia | last post by:
I have a vs2003 project (actually 44 of them) that I want to convert to VS2005 format. To fix a usercontrol file I created the Designer.vb file and moved the Inherited and Class ( change to...
0
by: John Krukoff | last post by:
-----Original Message----- One method which wouldn't require much python code, would be to run the XHTML through a simple identity XSL tranform with the output method set to HTML. It would...
0
by: M.-A. Lemburg | last post by:
On 2008-04-24 19:16, John Krukoff wrote: You could filter the XHTML through mxTidy and set the hide_endtags to 1: http://www.egenix.com/products/python/mxExperimental/mxTidy/ -- Marc-Andre...
1
sainathsagar
by: sainathsagar | last post by:
public void AudioConvert(){ FileStream fs = new FileStream(InputFileName, FileMode.Open, FileAccess.Read); NAudio.Wave.WaveFormat format = new NAudio.Wave.WaveFormat(); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.