Remove all characters in a string up to and including a specified pattern
-
Hi, can someone give any advice on the following problem I have in C# 2... I have a string such as "this_is_a test|XXmoretexthere". I need a bit of code that if I specify |xx as the sepertor, will return back to me everything after "|xx" so I have "moretexthere" as a result. The pattern I pass may vary content and length. The current pattern is held in a string variable. Should the pattern occur more than once in the string, I only need to return everything after the first occurrence. Whatever solution I use, it needs to be fast as it will run in a loop possibly many thousands of times. Many thanks for any advice.
-
Hi, can someone give any advice on the following problem I have in C# 2... I have a string such as "this_is_a test|XXmoretexthere". I need a bit of code that if I specify |xx as the sepertor, will return back to me everything after "|xx" so I have "moretexthere" as a result. The pattern I pass may vary content and length. The current pattern is held in a string variable. Should the pattern occur more than once in the string, I only need to return everything after the first occurrence. Whatever solution I use, it needs to be fast as it will run in a loop possibly many thousands of times. Many thanks for any advice.
A Regular Expression, or IndexOf and Substring.
-
Hi, can someone give any advice on the following problem I have in C# 2... I have a string such as "this_is_a test|XXmoretexthere". I need a bit of code that if I specify |xx as the sepertor, will return back to me everything after "|xx" so I have "moretexthere" as a result. The pattern I pass may vary content and length. The current pattern is held in a string variable. Should the pattern occur more than once in the string, I only need to return everything after the first occurrence. Whatever solution I use, it needs to be fast as it will run in a loop possibly many thousands of times. Many thanks for any advice.
it is only an idea you can use find and replace first to change any '|xx' with ';' then use string properties to find the place !!!!!
-
it is only an idea you can use find and replace first to change any '|xx' with ';' then use string properties to find the place !!!!!
He did say he wanted something fast: Yours involves two searches and two string copies. (Remember strings are immutable, so find and replace will create a new copy of the string, rather than alter the existing one.)
All those who believe in psycho kinesis, raise my hand. My :badger:'s gonna unleash hell on your ass. :badger:tastic!
-
Hi, can someone give any advice on the following problem I have in C# 2... I have a string such as "this_is_a test|XXmoretexthere". I need a bit of code that if I specify |xx as the sepertor, will return back to me everything after "|xx" so I have "moretexthere" as a result. The pattern I pass may vary content and length. The current pattern is held in a string variable. Should the pattern occur more than once in the string, I only need to return everything after the first occurrence. Whatever solution I use, it needs to be fast as it will run in a loop possibly many thousands of times. Many thanks for any advice.
string initialText = "this_is_a test|XXmoretexthere";
string searchString = "|XX";
int lastIndexFound = initialText.LastIndexOf(searchString);
if (lastIndexFound > 0)
{
MessageBox.Show(initialText.Substring(lastIndexFound + searchString.Length));
}
else
{
MessageBox.Show("Patternt not found");
}- Not sure if this is fast enough...
- Not sure if the search is case sensitive otherwise....
-
string initialText = "this_is_a test|XXmoretexthere";
string searchString = "|XX";
int lastIndexFound = initialText.LastIndexOf(searchString);
if (lastIndexFound > 0)
{
MessageBox.Show(initialText.Substring(lastIndexFound + searchString.Length));
}
else
{
MessageBox.Show("Patternt not found");
}- Not sure if this is fast enough...
- Not sure if the search is case sensitive otherwise....
-
Hi, can someone give any advice on the following problem I have in C# 2... I have a string such as "this_is_a test|XXmoretexthere". I need a bit of code that if I specify |xx as the sepertor, will return back to me everything after "|xx" so I have "moretexthere" as a result. The pattern I pass may vary content and length. The current pattern is held in a string variable. Should the pattern occur more than once in the string, I only need to return everything after the first occurrence. Whatever solution I use, it needs to be fast as it will run in a loop possibly many thousands of times. Many thanks for any advice.
Use this string[] str1 =str.Split(new string[] { "|xx" }, 2,StringSplitOptions.None); The second value that is str1[1] will have the value you are looking for. Do let me know if this is not the one you were looking for..
Jack Sparrow --------------------------------------
-
Use this string[] str1 =str.Split(new string[] { "|xx" }, 2,StringSplitOptions.None); The second value that is str1[1] will have the value you are looking for. Do let me know if this is not the one you were looking for..
Jack Sparrow --------------------------------------