1

I am currently trying to modify a script for a SSIS project to import data from a dynamic .txt file (sometimes colums are added).

I am new to c# and the only problem in the script is that it contains a string format expression that I really can't graps so my question is:

What does this do?

string _Statement = String.Format ("{0}(?=(?:[^{1}]*{1}[^{1}]*{1})*(?![^{1}]*{1}))"

The parameters are

  {0} = First line in the file containing all the column headers
  {1} = Semicolon delimiter

Any help in this would be much appreciated.

3 Answers 3

3

Since the same index is used repetitively, the same value is inserted.

So {0} will be replaced with

 First line in the file containing all the column headers

and all occurences of {1} will be replaced by

Semicolon delimiter

However, the code above seems to be incomplete since i'm missing the parameter list at the end of string.Format. Something like:

string _Statement = String.Format("{0}(?=(?:[^{1}]*{1}[^{1}]*{1})*(?![^{1}]*{1}))"
                                   , firstLine , ";");

Presuming that the line is: TEST-LINE this is the result:

"TEST-LINE(?=(?:[^;]*;[^;]*;)*(?![^;]*;))"
Sign up to request clarification or add additional context in comments.

1 Comment

Seems that i can't upvote due to lack of reputation, but this answer explains the question. Thank you!
0

The String.Format method here replaces all occurrences of {0} with First line in the file containing all the column headers and all occurrences of {1} with Semicolon delimiter. The resultant string will be a regular expression (regex) in this case.

1 Comment

Thank you that explains it! I guess that makes the question faulty due to the fact it is regex that I don't understand and not string.format. Now i have something to work with alteast!
0

String.Format formats your string, so each parameter within {} will be replaced with a value which you also have to specify. In your example, all values with {0} will be replaced with

First line in the file containing all the column headers

and all values with {1} will be replaced with

Semicolon delimiter

You have to specify this two values as parameters to String.Format, so your code should look like:

string first = "col1,col2,col3";
string second = ";";
string _Statement = String.Format("{0}(?=(?:[^{1}]*{1}[^{1}]*{1})*(?![^{1}]*{1}))", first, second);

And the result will be

_Statement = "col1,col2,col3(?=(?:[^;]*;[^;]*;)*(?![^;]*;))";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.