string temp_constraint = row["Constraint_Name"].ToString();
string split_string = "FK_"+tableName+"_";
string[] words = Regex.Split(temp_constraint, split_string);
I am trying to split a string using another string.
temp_constraint = FK_ss_foo_ss_fee
split_string = FK_ss_foo_
but it returns a single dimension array with the same string as in temp_constraint
Please help
Your split operation works fine for me:
Output:
I think the problem is that your variables are not set to what you think they are. You will need to debug to find the error elsewhere in your program.
I would also avoid using Split for this (both
RegexandString.Split). You aren’t really splitting the input – you are removing a string from the start. Split might not always do what you want. Imagine if you have a foreign key like the following:You want to get
ss_fee_FK_ss_foo_ss_beebut split would give youss_fee_andss_bee. This is a contrived example, but it does demonstrate that what you are doing is not a split.