We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

searching and replacing line feeds and carriage returns

I have written a search and replace routine for use with TX Text Control. It works in every instance with one exception.

When I attempt to search a line ending followed by a letter and replace it with a line ending followed by a capital letter, nothing happens.

How do I search special characters (i.e. line endings, tabs, etc.)?

Regards,
Ian

Code follows:

Public Sub SearchAndReplaceNoColor(ByVal strFileName As String, _
ByVal strSearch As String, _
ByVal strReplace As String, _
Optional ByVal boolWholword As Boolean = True, _
Optional ByVal boolCaseSensitive As Boolean = False)

'Set up minimal error handling
On Error GoTo errhandler

'Instantiate a new word document.
Dim doc As New WordDocument()

'Replace first instance
doc.ReplaceFirst = True

'The opened file has already been silently converted to a .doc file. Get the file name and open it.
If UCase(strFileName).Contains(".RTF") Then ConvertToWord(strFileName)
If UCase(strFileName).Contains(".TXT") Then ConvertToWord(strFileName)
If UCase(strFileName).Contains(".HTM") Then ConvertToWord(strFileName)
If UCase(strFileName).Contains(".HTML") Then ConvertToWord(strFileName)

strFileName = GetEverythingToTheLeftOfChar(strFileName, ".")
strFileName = strFileName & ".doc"

doc.Open(strFileName)

'Get the selection.
Dim selection As TextSelection() = doc.FindAll(strSearch, boolCaseSensitive, boolWholword)

'Iterate through each selection and replace the range.
For Each sel As TextSelection In selection
Dim range As WTextRange = sel.GetAsOneRange()
range.Text = strReplace
Next

'Save the document.
doc.Save("Sample.doc", FormatType.Doc)
'System.Diagnostics.Process.Start("Sample.doc")
frmMain.textControl1.Load("Sample.doc", TXTextControl.StreamType.MSWord)

errhandler:
Resume Next

End Sub





3 Replies

BP Bhuvaneswari P Syncfusion Team August 11, 2008 05:48 AM UTC

Hi Ian,

Thank you for your interest in Syncfusion products.

Currently we don't have support for find and replace the control characters. We have already logged it as a feature request and notified our development team. We will implement this feature in our forthcoming new version releases Volume4. We will get back to you once the feature is implemented.

Please let me know if you have any questions.

Best Regards,
Bhuvana





AD Administrator Syncfusion Team September 10, 2008 12:17 PM UTC

Hi Bhuvana!

I'm desperate for a search function that can select, copy, paste and replace pieces of text with control characters in them. In fact I can't do without it. I've been in contact with you before through this forum and you then suggested that I'd use bookmarks and the bookmarksnavigator to perform this task, which I've tried without achieving my goal (I'm having trouble with copying and pasting tables correctly, and the method seems shaky overall anyway). Is there some way that you could hurry the development of this function? We could be willing to pay for this.

Specifically, I would want somthing like this to work:

doc.Find(new Regex(@"\(.*)\", RegexOptions.Singleline));

This line of code should select a part in doc that could span several lines of text. Today this works for texts that reside on one single line, but fails otherwise.

I need an answer to this as quickly as possible, or we will be forced to switch to some other component.

Please contact me.

Best regards
Tobias Skillbäck
Canea AB




BP Bhuvaneswari P Syncfusion Team September 11, 2008 09:44 AM UTC

Hi Tobias,

Thank you for your interest in Syncfusion products.

We have already updated for this query in your incident post 49558, please follow up it.

Best Regards,
Bhuvana



Loader.
Live Chat Icon For mobile
Up arrow icon