Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by Camilla
at 2024-07-15 20:34:56
Point:500 Replies:7 POST_ID:828987USER_ID:11642
Topic:
C# Programming Language;Programming for ASP.NET;.NET
I have a long string and there's a text in it
Patient: Robert Someone (DOB 1/23/1927) or Patient: Test Tester (DOB 1/1/1920)
I want to get everything after Patient: up to the close parenthesis
I did this but this picks up everything after "Patient:"
Patient: Robert Someone (DOB 1/23/1927) or Patient: Test Tester (DOB 1/1/1920)
I want to get everything after Patient: up to the close parenthesis
I did this but this picks up everything after "Patient:"
string tobesearched = "Patient:"; string code = text.ToString().Substring(text.ToString().IndexOf(tobesearched) + tobesearched.Length); 1:2:
Author: Camilla replied at 2024-07-16 15:54:22
That worked, Kaufmed.
Author: Camilla replied at 2024-07-16 11:00:00
Let me try it. The issue is that Robert Test (DOB 1/23/1927) is repeated in 2 places. So, it takes the first occurrence, and but then looks for the second ")" and takes everything in between.
I'll try your code as well. I found another section of the document that I could use to get the info, but will still try your code.
I'll try your code as well. I found another section of the document that I could use to get the info, but will still try your code.
Accepted Solution
Expert: kaufmed replied at 2024-07-16 08:37:10
250 points EXCELLENT
If you are simply trying to find up to the closing paren, then a simply IndexOf should suffice:
e.g.
e.g.
string code = text.ToString().Substring(text.ToString().IndexOf(tobesearched) + tobesearched.Length);int closingParen = code.IndexOf(')');string match = code.Substring(0, closingParen); 1:2:3:
If you want to ultimately get each substring, then you repeatedly call IndexOf. It takes an additional parameter which specifies the starting index to begin searching from. You can use the closingParen variable for this.
e.g.
int startAt = closingParen + 1;closingParen = code.IndexOf(')', startAt);match = code.Substring(startAt, closingParen - startAt); 1:2:3:4:
Author: Camilla replied at 2024-07-16 07:27:02
Actually, it works but since that line is repeated twice, it gets everything in between.
Author: Camilla replied at 2024-07-16 07:20:26
Between didn't work.
I want this Patient: Robert Test (DOB 1/23/1927)
But it gets everything else after it too
Robert Test (DOB 1/23/1927)
Monday, July 14. 201407/14/2014 9:30 AM Retina Health Center
cc: Gary Test; Doctor Access Test
Doctor Access Test LI 3
Page 2 of 2
Patient: Robert Test (DOB 1/23/1927
I want this Patient: Robert Test (DOB 1/23/1927)
But it gets everything else after it too
Robert Test (DOB 1/23/1927)
Monday, July 14. 201407/14/2014 9:30 AM Retina Health Center
cc: Gary Test; Doctor Access Test
Doctor Access Test LI 3
Page 2 of 2
Patient: Robert Test (DOB 1/23/1927
Assisted Solution
Expert: Miguel replied at 2024-07-15 21:32:25
250 points EXCELLENT
Your code is only fetching the string after your left string delimiter "Patient:".
Your code needs to check for both before and after string. Check between method.
Usage:
Your code needs to check for both before and after string. Check between method.
Usage:
string leftDelimiter = "Patient:";string rightDelimiter = "(";string code = text.ToString().Between(leftDelimiter , rightDelimiter); 1:2:3:
Note: if required the extension method could be converted to static method. e.g. If your project uses .NET 3.0 or earlier.
Expert: duncanb7 replied at 2024-07-15 21:08:42
Patient: S*\)
Try this regular expression
Duncan
Try this regular expression
Duncan