Get text between two defined characters

Hi,

I was wondering if is possible to get the text that is marked with some characters. For example, if I have something like:
" This is a paragraph and I have a [text_enclosed] between brakets." So, I want to get the text (I which i don`t know) that is inside the brackets (text_enclosed).

Thanks for your assistance,
Kind regards,

Juan J. 



3 Replies

DB Dilli Babu Nandha Gopal Syncfusion Team July 24, 2018 09:21 AM UTC

Hi Juan, 

Thank you for contacting Syncfusion support. 

Yes, it is possible retrieve a text in between characters(brackets) using Find functionality in Essential DocIO. Please find the code example to retrieve a text in between brackets. 
//Creates a new Word document instance 
WordDocument document = new WordDocument(); 
document.EnsureMinimal(); 
document.LastParagraph.AppendText("This is a paragraph and I have a [text_enclosed] between brakets."); 
//Find the first occurrence of a particular text in the document 
TextSelection textSelection = document.Find(new Regex(@"(?<=\[)(.*?)(?=\])")); 
//Get the found text as single text range 
WTextRange textRange = textSelection.GetAsOneRange(); 
//Get the in between text 
string inBetweenText = textRange.Text; 
document.Close(); 

To know more about Find operations with Regex pattern, kindly refer the following API documentation links 
1.      Find(Regex) 
2.      FindAll(Regex) 

Please let us know whether your requirement is fulfilled. 

Regards, 
Dilli babu. 



JJ Juan Jose Uribe July 24, 2018 01:16 PM UTC

Yes, excellent. Thanks so much.

Regards,

Juan J.


DB Dilli Babu Nandha Gopal Syncfusion Team July 25, 2018 04:51 AM UTC

Hi Juan, 
 
We are glad to know that your requirement is fulfilled. Kindly let us know if you need any further assistance on this. 
 
Regards, 
Dilli babu 


Loader.
Up arrow icon