Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string by repeating keyword

Tags:

c#

I have a repeating text file that is similar to this, which I am looking to break up into individual files based on the 'Tx' indicator .... Any thoughts on how I could achieve this?

Tx1
some data 
some data
Tx2
some data 
some data
Tx3
some data 
some data
like image 685
smietanski Avatar asked May 11 '26 13:05

smietanski


1 Answers

1.Load a the file contents to memory as a string

2.Use RegEx to split

string[] lines = Regex.Split(str, "Tx^[0-9]");

3.Save each line different file

like image 187
Shachaf.Gortler Avatar answered May 13 '26 02:05

Shachaf.Gortler