char[] annoyance...

Regan Heath regan at netwin.co.nz
Mon Apr 10 15:25:34 PDT 2006


On Mon, 10 Apr 2006 18:51:00 +1000, Derek Parnell <derek at psych.ward> wrote:
> On Mon, 10 Apr 2006 17:54:25 +1000, S. Chancellor  
> <dnewsgr at mephit.kicks-ass.org> wrote:
>
>
>> Erps, I should skim your post better.  Yeah that's a problem, you can  
>> fix it without the other if though.
>>
>> for(int i = 0; i + 2 < line.length; i++) {
>>
>>
>> Or am I still missing something?  Hehe.
>
> No, that is fine and along the same lines as the original code. As is
>
>     for(int i = 0; i < (cast(int)line.length)-2; i++) {
>
> however I still prefer telling the code reader what I'm doing etc... in  
> clear, simple code. Although your code will work, it just isn't as clear  
> at first glance as
>
>    if (line.length >= 2)
>    {
>       ...
>    }
>
> but of course an even better way (IMHO) ...
>
>      int posn = std.string.find(line, "||");
>      if (posn >= 0)
>      {
>          // etc ....
>      }

In my case there were several || on the lines, eg.

..etc..||<A>_desc||..etc..||<B>_desc||..etc..

and I'm actually rewriting them as:

..etc..||thing(<A>_desc)||..etc..||thing(<B>_desc)||..etc..

but, yeah, it's possible to use find. :)

Regan




More information about the Digitalmars-d mailing list