R8VI
asked on
c# find value in string
Hi,
I have the string below
AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = \r\n),\r\n(\r\n
so that CTDT.slangeid = nothing at the moment
What i want to do is get to that place and then assign the string x and then continue with the rest of the things in the string.
Please help
Thanks,
R8VI
I have the string below
AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = \r\n),\r\n(\r\n
so that CTDT.slangeid = nothing at the moment
What i want to do is get to that place and then assign the string x and then continue with the rest of the things in the string.
Please help
Thanks,
R8VI
can you be more clear
Can you please explain your scenario in a bit detail with c# code.
i am trying to guess and assume that your string will have spaces as shown above
what i will do is find the text CTDT.slangeid = \r\n in the string and replace it with the other string using string.replace function
what i will do is find the text CTDT.slangeid = \r\n in the string and replace it with the other string using string.replace function
ASKER
ill try
string test = 'AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = \r\n),\r\n(\r\n '
string x = 2
So i want to get to point CTDT.slangeid = and assign x and then have another string called y which looks like
y = 'AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid =2 \r\n),\r\n(\r\n '
Thanks,
R8VI
string test = 'AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = \r\n),\r\n(\r\n '
string x = 2
So i want to get to point CTDT.slangeid = and assign x and then have another string called y which looks like
y = 'AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid =2 \r\n),\r\n(\r\n '
Thanks,
R8VI
If you're able, it might be better to store tokens in that string that could then be replaced with actual values...e.g. store the string as AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = {0} \r\n),\r\n(\r\n then in your code you could easily do:
string input = "AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = {0} \r\n),\r\n(\r\n";
string slangeid = "hello world";
string complete = String.Format(input, slangeid);
Or, put a token in like $*LANGEID*$ and do find replace:
string input = "AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = $*LANGEID*$ \r\n),\r\n(\r\n";
string langeid = "Hello World";
string complete = input.Replace("$*LANGEID*$ ", langeid);
Otherwise, you can use String.IndexOf or a regular expression to find CTDT.slangeid.
string input = "AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = {0} \r\n),\r\n(\r\n";
string slangeid = "hello world";
string complete = String.Format(input, slangeid);
Or, put a token in like $*LANGEID*$ and do find replace:
string input = "AND ACTD.ArtId =A.ArId\t\r\n\t\t\tAND CTDT.slangeid = $*LANGEID*$ \r\n),\r\n(\r\n";
string langeid = "Hello World";
string complete = input.Replace("$*LANGEID*$
Otherwise, you can use String.IndexOf or a regular expression to find CTDT.slangeid.
you can use following
string y=input.Replace("CTDT.slan geid =","CTDT.slangeid ="+x)
string y=input.Replace("CTDT.slan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am accepting this as this is what worked for me