Skip to content

LastIndexOf赋值循序有误 #12

@aidoTank

Description

@aidoTank

public int LastIndexOf(string value)
{
int idx = -1;
int last_find = -1;
while (true)
{
idx = internal_index_of(this._value, value, idx + value.Length);
last_find = idx;
if (idx == -1 || idx + value.Length >= this._value.Length)
break;
}
return last_find;
}
当internal_index_of() 返回-1时, last_find = idx;会覆盖上次的值,导致最终返回-1,
应该调整至if判断之后:
public int LastIndexOf(string value)
{
int idx = -1;
int last_find = -1;
while (true)
{
idx = internal_index_of(this._value, value, idx + value.Length);
if (idx == -1 || idx + value.Length >= this._value.Length)
break;
last_find = idx;
}
return last_find;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions