1

I have a string:

string fileName = VAH007157100_REINSTMT_20d5fe49.tiff

I want to split this at the end of REINSTMT.

string splittedFileName = fileName.split("REINSTMT")[0];

The above does not work.

How would I go about splitting it to grab everything from the left side of the word "REINSTMT"?

3 Answers 3

2

Try this

string splittedFileName = fileName.Split(new string[]{"REINSTMT"},
                                                  StringSplitOptions.None)[0];
Sign up to request clarification or add additional context in comments.

Comments

0

In order to split based on a string rather than a char, you need to provide a second argument. See the documentation here.

What you probably want is

string splittedFileName = fileName.split(new string[] {"REINSTMT"}, StringSplitOptions.None)[0]; 

Comments

0

Another way would be with substring:


string fileName = "VAH007157100_REINSTMT_20d5fe49.tiff";
string splittedFileName = fileName.Substring(0, fileName.IndexOf("REINSTMT"));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.