@byxiaoxie2月前

08/30
23:26
Home

C# ini配置文件读写

ini.cs 源代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace ini_config
{
    /// <summary>
    /// ini文件类
    /// </summary>
    public class IniFile
    {
        private string m_FileName;

        public string FileName
        {
            get { return m_FileName; }
            set { m_FileName = value; }
        }

        [DllImport("kernel32.dll")]
        private static extern int GetPrivateProfileInt(
            string lpAppName,
            string lpKeyName,
            int nDefault,
            string lpFileName
            );

        [DllImport("kernel32.dll")]
        private static extern int GetPrivateProfileString(
            string lpAppName,
            string lpKeyName,
            string lpDefault,
            StringBuilder lpReturnedString,
            int nSize,
            string lpFileName
            );

        [DllImport("kernel32.dll")]
        private static extern int WritePrivateProfileString(
            string lpAppName,
            string lpKeyName,
            string lpString,
            string lpFileName
            );

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="aFileName">Ini文件路径</param>
        public IniFile(string aFileName)
        {
            this.m_FileName = aFileName;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public IniFile()
        { }

        /// <summary>
        /// [扩展]读Int数值
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="def">默认值</param>
        /// <returns></returns>
        public int ReadInt(string section, string name, int def)
        {
            return GetPrivateProfileInt(section, name, def, this.m_FileName);
        }

        /// <summary>
        /// [扩展]读取string字符串
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="def">默认值</param>
        /// <returns></returns>
        public string ReadString(string section, string name, string def)
        {
            StringBuilder vRetSb = new StringBuilder(2048);
            GetPrivateProfileString(section, name, def, vRetSb, 2048, this.m_FileName);
            return vRetSb.ToString();
        }

        /// <summary>
        /// [扩展]写入Int数值,如果不存在 节-键,则会自动创建
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="Ival">写入值</param>
        public void WriteInt(string section, string name, int Ival)
        {

            WritePrivateProfileString(section, name, Ival.ToString(), this.m_FileName);
        }

        /// <summary>
        /// [扩展]写入String字符串,如果不存在 节-键,则会自动创建
        /// </summary>
        /// <param name="section">节</param>
        /// <param name="name">键</param>
        /// <param name="strVal">写入值</param>
        public void WriteString(string section, string name, string strVal)
        {
            WritePrivateProfileString(section, name, strVal, this.m_FileName);
        }

        /// <summary>
        /// 删除指定的 节
        /// </summary>
        /// <param name="section"></param>
        public void DeleteSection(string section)
        {
            WritePrivateProfileString(section, null, null, this.m_FileName);
        }

        /// <summary>
        /// 删除全部 节
        /// </summary>
        public void DeleteAllSection()
        {
            WritePrivateProfileString(null, null, null, this.m_FileName);
        }

        /// <summary>
        /// 读取指定 节-键 的值
        /// </summary>
        /// <param name="section"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string IniReadValue(string section, string name)
        {
            StringBuilder strSb = new StringBuilder(256);
            GetPrivateProfileString(section, name, "", strSb, 256, this.m_FileName);
            return strSb.ToString();
        }

        /// <summary>
        /// 写入指定值,如果不存在 节-键,则会自动创建
        /// </summary>
        /// <param name="section"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public void IniWriteValue(string section, string name, string value)
        {
            WritePrivateProfileString(section, name, value, this.m_FileName);
        }
    }
}

阅读全文 →

C# ini配置文件读写

@byxiaoxie2月前

08/5
16:00
Home

Python3 取用户目录与判断文件是否存在

源代码:

#!/usr/bin/nev python3
# -*- coding: utf-8 -*-

import os # 先引用 os 模块

user_dir = os.getenv('APPDATA') # 利用 os 模块获取Windows用户 appdata 路径
print(user_dir) # 输出查看路径是否正确

if os.access(user_dir,os.F_OK): # 判断文件是否存在 os.F_OK 用法请看下面
    print("文件存在")
else:
    print("文件不存在")

阅读全文 →

Python3 取用户目录与判断文件是否存在

@byxiaoxie3月前

07/22
16:01
Home

Python3入门爬虫

HTML源代码:

<html xmlns=http://www.w3.org/1999/xhtml>
	<meta http-equiv=Content-Type content="text/html;charset=utf-8">
    <title>爬虫测试</title>
	
    <head>
        <body>
            <h1>任务1:把[P]标签内容利用爬虫全部读取出来.</h1>
            <h2>任务2:把[A]标签连接全部利用爬虫读取出来.</h2>
            <h2>任务3:把[Img]标签图片地址全部读取出来.</h2>
            <h1>任务4:读取完每一个后利用[\n]换行.</h1>
            <hr>
            <p>Test_P_1</p>
            <p>Test_P_2</p>
            <p>Test_P_3</p>
            <p>Test_P_4</p>
            <p>Test_P_5</p>
            <hr>
            <a href="https://baidu.com">连接1_baidu</a>
            <a href="https://byxiaoxie.com">连接2_byxiaoxie</a>
            <a href="http://xz.nicokun.com">连接3_nicokun</a>
            <hr>
            <img src="img_1.jpg" alt="图片1">
            <img src="img_2.jpg" alt="图片2">
            <img src="img_3.jpg" alt="图片3">
        </body>
    </head>
</html>

阅读全文 →

Python3入门爬虫

@byxiaoxie7月前

03/14
10:03
Home

C语言学习(弃坑)

变量类型与输出类型:

int d = 10; //整数型
long ld = 10; //长整型
unsigned ud = 65535 //无符号整型
float f = 1.0; //单精度浮点型
double lf = 1E2; //双精度浮点型
char p = 'C language'; //字符串
char *p = "C language"; //指针字符串

printf("%s\n",p); //字符串输出
printf("%d\n",p); //整数型输出
printf("%f\n",p); //单精度浮点输出
printf("%o\n",p); //八进制输出
printf("%x\n",p); //十六进制输出
printf("%ld\n",p); //长整型输出
printf("%lf\n",p); //双精度浮点输出 
printf("%c\n",p); //字符型输出 
//中文输出
const char text[] = "测试"; 
printf("\n",printf(text));

阅读全文 →

C语言学习(弃坑)

@byxiaoxie7月前

03/30
00:29
Home

Python 2.7 与 Python 3 从零教学

#hello.py
#!/usr/bin/env python
# -- coding: utf-8 --  #编码格式为 utf-8
# -*- coding: utf-8 -*- #编码格式为 utf-8

print 'Hello World'    #输出 Hello World
print 'Hello','World'  #print用逗号“,”分开会输出一个空格 ,所以会显示成 Hello World
print 'HelloWorld'     #输出 HelloWorld

name = raw_input("请输入你的名字:") #raw_input 输入 并把输入的值保存到变量 name
print name #输出变量 name 的值
print 'Hello,',name #输出 Hello 再输出 name 变量的值

#输入一个整数并判断 a 的值是否大于等于0
a = int(raw_input('请输入一个整数:'))
if a>=0:
    print a
else:
    print a

阅读全文 →

Python 2.7 与 Python 3 从零教学

加载中……