Parsing tnsnames.ora in Visual C# 2008

后端 未结 3 1834
慢半拍i
慢半拍i 2020-12-11 20:26

How I parse tnsnames.ora file using Visual C# (Visual Studio 2008 Express edition) to get the tnsnames ? For instance, my tnsnames.ora file contains

ORCL =
         


        
3条回答
  •  死守一世寂寞
    2020-12-11 20:54

    public List ReadTextFile(string FP)
    {
    
        string inputString;
        List List = new List();
    
        try
        {
            StreamReader streamReader = File.OpenText(FP.Trim()); // FP is the filepath of TNS file
    
            inputString = streamReader.ReadToEnd();
            string[] temp = inputString.Split(new string[] {Environment.NewLine},StringSplitOptions.None);
    
            for (int i = 0; i < temp.Length ;i++ )
            {
                if (temp[i].Trim(' ', '(').Contains("DESCRIPTION"))
                {                   
                    string DS = temp[i-1].Trim('=', ' ');
                    List.Add(DS);
                }             
    
            }
            streamReader.Close();
        }
        catch (Exception EX)
        {
        }
    
    
        return List;
    
    }
    

提交回复
热议问题