Parse without string split

前端 未结 2 1161
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 08:10

This is a spin-off from the discussion in some other question.

Suppose I\'ve got to parse a huge number of very long strings. Each string contains a sequence of

2条回答
  •  借酒劲吻你
    2021-01-05 08:12

    if you want to do it really fast, i would use a state machine

    this could look like:

    enum State
    {
        Separator, Sign, Mantisse etc.
    }
    State CurrentState = State.Separator;
    int Prefix, Exponent, Mantisse;
    foreach(var ch in InputString)
    {
        switch(CurrentState)
        { // set new currentstate in dependence of ch and CurrentState
            case Separator:
               GotNewDouble(Prefix, Exponent, Mantisse); 
    
    
        }
    
    }
    

提交回复
热议问题