There is such a task: add the secretCode variable to a string of this type OBR | 1 | Source // 001011 // A11.00.00.111 // 1.1.1 ^ TSI | 100011 ^ SHAPIRO | A10.10.001.101 ^ text on the length of code ^^ 111B ^ text on the length of code ||| 20110610092100 | + secretCode + ||||| ^ || text of arbitrary length | ^ || Y8359833Fg = |||||||| ^^^^|||||||

Please tell me how to do this?

  • In the example, I showed how it should be done (yes, using concatenation), the default is a string without + secretCode +, and the question is how to add this variable to the place where it is in the example - dexploizer
  • Refine your question, it is unclear what you want. Also, you did not indicate what you tried and what you did. - Vadim Ovchinnikov
  • I know that it seems to be possible through the regulars, but my problem is in their misunderstanding. - dexploizer
  • You have the desired result in the question, but there is no source data. Therefore, you were offered concatenation as the simplest solution. If it does not fit, then source data is needed. By the way, I could be mistaken, and the drain given in the question is the initial data, and secretCode is the label where to insert the code. In this case, the String.Replace method is suitable, without any regularizers. - Uranus

1 answer 1

You have a text with delimiters. SecretCode explicitly in a certain "cell" should be.
Split the separator, replace the contents of a specific cell, glue back.

var secretCodeIndex=8; var elements=data.Split('|'); elements[secretCodeIndex]=secretCode; data=string.Join("|",elements); 

http://ideone.com/MCVoT7

  • Thank you!) - dexploizer