Link to home
Start Free TrialLog in
Avatar of R8VI
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
Avatar of kswathi
kswathi
Flag of India image

can you be more clear
Avatar of contactnaeem
contactnaeem

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
Avatar of R8VI

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
Avatar of Todd Gerbert
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.

you can use following

string y=input.Replace("CTDT.slangeid =","CTDT.slangeid ="+x)
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of R8VI

ASKER

I am accepting this as this is what worked for me