原来的程序是用三个Text文本框读写三行IP数据,代码如下:
         IniFile.WriteIniVal("IPADDRESS",IP1,m_ip1,path);
IniFile.WriteIniVal("IPADDRESS","IP2",m_ip2,path);
IniFile.WriteIniVal("IPADDRESS","IP3",m_ip3,path);
ini文件的效果如下:
[IPADDRESS]
IP1=122.0.201.129
IP2=127.0.0.3
IP3=127.0.0.1
现在我想只用一个Text文本框循环输入数据,怎么实现?谢谢!!

解决方案 »

  1.   

    只能用GetPrivateProfileString一个key一个key的读写
      

  2.   

    用sscanf:★.sscanf高级用法( sscanf用法以及正则表达式的运用 )
        if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2 ) 中间那堆字符什么意思吗 
        %[^=] 表示接受的串里面没有=,也就是直到字符串line结束或者出现了第一个=,所扫描过的内容都会被接受
        \"是转义字符
        例如
        line="test=TEST";
        char s[100];
        sscanf(line,"%[^=]",s);
        s就被添进了字符串test
        
        支持集合操作
        %[a-z] 表示匹配a到z中任意字符,贪婪性(尽可能多的匹配) 
        %[aB'] 匹配a、B、'中一员,贪婪性 
        %[^a] 匹配非a的任意字符,贪婪性    
        
        1. sscanf("123456","%s",str);                       // 常见用法。
        2. sscanf("123456","%4s",str);                      // 取指定长度的字符串。如在下例中,取最大长度为4字节的字符串。
        3. sscanf("123456abcdedf","%[^]",str);              // 取到指定字符为止的字符串。如在下例中,取遇到空格为止字符串。
      4. sscanf("123456abcdedfBCDEF","%[1-9a-z]",str);    // 取仅包含指定字符集的字符串。如在下例中,取仅包含1到9和小写字母的字符串。
      5. sscanf("123456abcdedfBCDEF","%[^A-Z]",str);      // 取到指定字符集为止的字符串。如在下例中,取遇到大写字母为止的字符串。    %[ ] 的用法:%[ ]表示要读入一个字符集合, 如果[ 后面第一个字符是”^”,则表示反意思。
            [ ]内的字符串可以是1或更多字符组成。空字符集(%[])是违反规定的,可
            导致不可预知的结果。%[^]也是违反规定的。
            
        %[a-z] 读取在 a-z 之间的字符串,如果不在此之前则停止,如
            char s[]="hello, my friend” ; // 注意: ,逗号在不 a-z之间
            sscanf( s, “%[a-z]”, string ) ; // string=hello
                      
        %[^a-z] 读取不在 a-z 之间的字符串,如果碰到a-z之间的字符则停止,如
            char s[]="HELLOkitty” ; // 注意: ,逗号在不 a-z之间
            sscanf( s, “%[^a-z]”, string ) ; // string=HELLO
                      
        %*[^=] 前面带 * 号表示不保存变量。跳过符合条件的字符串。
            char s[]="notepad=1.0.0.1001" ;
            char szfilename [32] = "" ;
            int i = sscanf( s, "%*[^=]", szfilename ) ; 
            // szfilename=NULL,因为没保存
            int i = sscanf( s, "%*[^=]=%s", szfilename ) ; 
            // szfilename=1.0.0.1001
        
        %40c 读取40个字符
        %[^=] 读取字符串直到碰到’=’号,’^’后面可以带更多字符,如:
            char s[]="notepad=1.0.0.1001" ;
            char szfilename [32] = "" ;
            int i = sscanf( s, "%[^=]", szfilename ) ; 
            // szfilename=notepad 
            如果参数格式是:%[^=:] ,那么也可以从 notepad:1.0.0.1001读取notepad
                
        附: 常见正则表达式( http://regexlib.com/Search.aspx?k=IP+address&c=-1&m=-1&ps=20 ) 
            1.Description RegExp for validating the format of IP Addresses. This works great with the ASP.NET RegularExpressionValidator server control. 
                Expression ^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$
                Matches 127.0.0.1 | 255.255.255.0 | 192.168.0.1 
                Non-Matches 1200.5.4.3 | abc.def.ghi.jkl | 255.foo.bar.1 
            2.Description Matches e-mail addresses, including some of the newer top-level-domain extensions, such as info, museum, name, etc. Also allows for emails tied directly to IP addresses. 
                Expression ^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$ 
                Matches [email protected] | [email protected] | [email protected] 
                Non-Matches broken@@example.com | [email protected] | [email protected] 
            3.Description This matches an IP address, putting each number in its own group that can be retrieved by number. If you do not care about capturing the numbers, then you can make this shorter by putting everything after ^ until immediately after the first \. in a group ( ) with a {3} after it. Then put the number matching regex in once more. It only permits numbers in the range 0-255.  
                Expression ^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$ 
                Matches 0.0.0.0 | 255.255.255.02 | 192.168.0.136 
                Non-Matches 256.1.3.4 | 023.44.33.22 | 10.57.98.23. 
      

  3.   

    CString strTemp;
    for(int i=1;;i++)
    {
    strTemp.Format("IP%d",i);
    if(0 == GetPrivateProfileString(....))
    break;
    }