System.IO.StringReader.ReadLine C# (CSharp) Method

ReadLine() public method

public ReadLine ( ) : string
return string
        public override string ReadLine()
        {
            if (_s == null)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_ReaderClosed);
            }

            int i = _pos;
            while (i < _length)
            {
                char ch = _s[i];
                if (ch == '\r' || ch == '\n')
                {
                    string result = _s.Substring(_pos, i - _pos);
                    _pos = i + 1;
                    if (ch == '\r' && _pos < _length && _s[_pos] == '\n')
                    {
                        _pos++;
                    }

                    return result;
                }

                i++;
            }

            if (i > _pos)
            {
                string result = _s.Substring(_pos, i - _pos);
                _pos = i;
                return result;
            }

            return null;
        }

Usage Example

Exemplo n.º 1
0
        private void BuildChangeSetDetails(string history)
        {
            using (var reader = new StringReader(history))
            {
                // skip 2 lines
                reader.ReadLine();
                reader.ReadLine();

                var regex = new Regex(@"(\d+)\s+.+\s([\w\\]+).+\D(\d{1,2}/\d{1,2}/\d{4}).+");

                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var m = regex.Match(line);

                    int changesetId = int.Parse(m.Groups[1].Value);

                    ChangeSetDetails cs;
                    var keyExists = this.csd.TryGetValue(changesetId, out cs);
                    if (!keyExists)
                    {
                        string username = m.Groups[2].Value;
                        string timestamp = m.Groups[3].Value;
                        cs = new ChangeSetDetails(changesetId, timestamp, username);

                        this.csd[changesetId] = cs;
                    }
                }
            }
        }
All Usage Examples Of System.IO.StringReader::ReadLine