Click here to Skip to main content
15,881,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,I'm currently making a smart word processor and I want to put a space between word and the quotation marks for the all words in a rich text box by aone button click like this,
If the sentence is,
"hi,code project"

It should display like this,(see the spaces carefully)
" hi,code project "

Can someone helpme?
-Regards

[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 29-Feb-12 19:59pm
v2

<pre>Dim textToModify As String = rtfText.Text
Dim stringPattern As String = """
Dim replaceString As String = " ""
rtfText.Text = System.Text .RegularExpressions .Regex .Replace(textToModify ,_ stringPattern,replaceString) "</pre>
 
Share this answer
 
Comments
Kschuler 6-Mar-12 10:42am    
I'm not sure that your string patterns are correct, but I agree that regular expressions are the way to go.
Here's some pseudo code on what you need. It basically loops through each character in the string (keeping track of if it's "inside" quotes or not) and appends/prepends the space when opening/closing the quotes.

OutputText = ""
insideQuote = False

For Each Character In String

  If Character = """" Then
    If insideQuote Then 
      OutputText = OutputText + " " + Character
    Else
      OutputText = OutputText + Character + " "
    End If
    insideQuote = Not insideQuote
  Else
    OutputText = OutputText + Character
  End If

Next
 
Share this answer
 
Dear anuradhapriyankara,
Its very easy, assign the spaces in first and last characters of richtextbox text as a string. F Y I, find the below code,
VB
dim text as string = " " & richtxtbox.text.tostring() & " "
MessageBox.show(text.tostring())

Regards,
Bluesathish
 
Share this answer
 
Comments
Kumar from madras 1-Mar-12 2:18am    
Its correct, then why its got 1. Take 5. whats wrong OriginalGriff?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900