Click here to Skip to main content
15,898,938 members
Home / Discussions / C#
   

C#

 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Dave Kreskowiak12-Sep-16 13:09
mveDave Kreskowiak12-Sep-16 13:09 
GeneralRe: Windows Shell - Prevent Folder & File Operations Pin
Eddy Vluggen13-Sep-16 3:22
professionalEddy Vluggen13-Sep-16 3:22 
AnswerRe: Windows Shell - Prevent Folder & File Operations Pin
Bernhard Hiller12-Sep-16 21:22
Bernhard Hiller12-Sep-16 21:22 
AnswerRe: Windows Shell - Prevent Folder & File Operations Pin
Nathan Minier13-Sep-16 1:41
professionalNathan Minier13-Sep-16 1:41 
QuestionGetting Index Of Delimiters After A String Pin
MadDashCoder11-Sep-16 17:11
MadDashCoder11-Sep-16 17:11 
AnswerRe: Getting Index Of Delimiters After A String Pin
BillWoodruff11-Sep-16 19:31
professionalBillWoodruff11-Sep-16 19:31 
GeneralRe: Getting Index Of Delimiters After A String Pin
MadDashCoder11-Sep-16 19:56
MadDashCoder11-Sep-16 19:56 
GeneralRe: Getting Index Of Delimiters After A String Pin
BillWoodruff12-Sep-16 4:50
professionalBillWoodruff12-Sep-16 4:50 
Hi, I made the assumption, in replying to your question, that you were parsing a file one-line-at-time, so the issue of possible multiple bracket characters would not arise.

But, there's a relatively easy way to confine your search to the first ] character after the first [ character found:
C#
private string test = @"Sample1[Model:M1; Year:1990]Sample2[Model:M3; Year:1997];"

List<Point> bracketIndexes = new List<Point>();

char rBrack = '[';
char lBrack = ']';

int loc = 0;
int limit = test.Length;
int brackStart, brackEnd;

while (loc < limit)
{
    brackStart = test.IndexOf(rBrack, loc);
    if (brackStart == -1) break;
    
    brackEnd = test.IndexOf(lBrack, brackStart + 1);
    if (brackEnd == -1) break;
    
    loc += brackEnd;
    
    bracketIndexes.Add(new Point(brackStart, brackEnd));
    
    loc++;
}

foreach (Point pt in bracketIndexes)
{
    Console.WriteLine("{0} at {1} : {2} at {3}", test[pt.X], pt.X, test[pt.Y], pt.Y);
};

// actual output to Console:
//[ at 7 : ] at 27
//[ at 35 : ] at 55
Notes:

1. I used a 'Point structure here to hold the discovered indexes for convenience ... as an alternative to using a Struct or a Tuple.

2. I'm allergic to writing a 'while loop without an exit condition, but, in this case, the loop is going to be exited the first time either of the two calls to 'IndexOf return -1.

3. Somebody could come along and show a much shorter way of doing this with RegEx (?), but since i am "RegEx challenged," that's a guess. Similarly, you could use Linq here, perhaps some form of 'GroupBy, but, my experience is that this type of operation is best done with loops: better performance. That opinion is one I have formed more from reading opinions of people I regard as at a level of technical depth much deeper than mine ... than from personal experimentation.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

AnswerRe: Getting Index Of Delimiters After A String Pin
OriginalGriff11-Sep-16 23:26
mveOriginalGriff11-Sep-16 23:26 
GeneralRe: Getting Index Of Delimiters After A String Pin
BillWoodruff12-Sep-16 5:05
professionalBillWoodruff12-Sep-16 5:05 
GeneralRe: Getting Index Of Delimiters After A String Pin
OriginalGriff12-Sep-16 5:09
mveOriginalGriff12-Sep-16 5:09 
AnswerRe: Getting Index Of Delimiters After A String Pin
#realJSOP12-Sep-16 8:49
professional#realJSOP12-Sep-16 8:49 
GeneralRe: Getting Index Of Delimiters After A String Pin
MadDashCoder13-Sep-16 8:02
MadDashCoder13-Sep-16 8:02 
Questioncompare two textboxes (string) - need help Pin
mar malaza11-Sep-16 1:04
mar malaza11-Sep-16 1:04 
GeneralRe: compare two textboxes (string) - need help Pin
harold aptroot11-Sep-16 1:41
harold aptroot11-Sep-16 1:41 
AnswerRe: compare two textboxes (string) - need help Pin
#realJSOP11-Sep-16 3:30
professional#realJSOP11-Sep-16 3:30 
AnswerRe: compare two textboxes (string) - need help Pin
V.11-Sep-16 21:10
professionalV.11-Sep-16 21:10 
QuestionHow is check the date of a valid dateEdit ? Pin
Member 245846710-Sep-16 23:42
Member 245846710-Sep-16 23:42 
AnswerRe: How is check the date of a valid dateEdit ? Pin
OriginalGriff11-Sep-16 0:03
mveOriginalGriff11-Sep-16 0:03 
AnswerRe: How is check the date of a valid dateEdit ? Pin
#realJSOP11-Sep-16 3:21
professional#realJSOP11-Sep-16 3:21 
QuestionGroup Sequance patterns with Linq Pin
Member 121069269-Sep-16 1:27
Member 121069269-Sep-16 1:27 
AnswerRe: Group Sequance patterns with Linq Pin
Richard Deeming9-Sep-16 2:02
mveRichard Deeming9-Sep-16 2:02 
GeneralRe: Group Sequance patterns with Linq Pin
Member 121069269-Sep-16 2:10
Member 121069269-Sep-16 2:10 
AnswerRe: Group Sequance patterns with Linq Pin
#realJSOP9-Sep-16 2:14
professional#realJSOP9-Sep-16 2:14 
GeneralRe: Group Sequance patterns with Linq Pin
Member 121069269-Sep-16 2:19
Member 121069269-Sep-16 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.