Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have string like :

Patient Name : Ankit kumar mishra
some extra string


in my cs page i want some logic like this : If this string sontains Patient Name : Then

i want to remove text up to patient last name which is mishra.. but string after last name will be remains same

Here Firstname =Ankit ,middle name = kumar, Last name= mishra.
Posted

Hi,

You can use (1) If you can use substring method or (2) regular expression for this.

http://www.regular-expressions.info/[^]
 
Share this answer
 
hi,

You can write logic like..

Count the no. of spaces in the string, and then find the 2nd space position then from that position on wards to last remove the characters.

using
C#
Substring()
and
C#
Split()
functions
 
Share this answer
 
I solved it with help of VijayChauhan comment..

C#
string sString = "Mrinal Kumar Jha\r\n Rest of the string";
int icount=0;
int iCountIndex = 0;
foreach (char c in sString)
{
  if (c.ToString() != "\r")
  {
    iCountIndex++; // 16th index
  }
  else
  {
    break;
  }
}
sString = sString.Remove(0, iCountIndex);
 
Share this answer
 
Strings are immutable. You cannot modify any strings.

I think you need something very different: to obtain one string from another, with some text removed, such as
C#
string name = //...
name = name.Replace("Mishra", string.Empty); // perhaps the sample is too simplified, but you got the idea


In this line, you create a brand new string object; old object will be eventually discarded (by Garbage Collector, some time later). The variable name will loose its referential identity as a result of operation, that is, not only the referenced object is new, but, as a result, the reference itself is new.

(You should understand here, that if you have a variable/field of reference type, it consist of two parts: a reference as object and the referenced object, the reference object always stored on heap, the reference can be somewhere else.)

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900