WinForm中richTextBox1换行
richTextBox1.Text += "【" + DateTime .Now.ToLongTimeString() + "】" + log;
this.richTextBox1.AppendText( Environment.NewLine);
WinForm中richTextBox1换行
richTextBox1.Text += "【" + DateTime .Now.ToLongTimeString() + "】" + log;
this.richTextBox1.AppendText( Environment.NewLine);
Linux查找并删除命令
find / -name "apache2" -print -exec rm -fr {} \;
ubuntu或centos No package ‘glib-2.0’ found解决办法
CentOS:
在root 下运行 yum install libgnomeui-devel
ubuntu :
sudo apt-get install libperl-dev
sudo apt-get install libgtk2.0-dev
VC 检测文件是否存在
bool IsExistFile(LPCSTR pszFileName )
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(pszFileName , &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
return false;
else
{
FindClose(hFind);
return true;
}
return false;
}
VC库函数获取当前EXE所在的路径
TCHAR cfgPath[ MAX_PATH];
GetModuleFileName(NULL , cfgPath, MAX_PATH);
PathAppend(cfgPath, "..\\config.ini" );
wireshark只抓HTTP包 http and tcp.port == 80
delphi7使用idhttp获取https的页面代码
procedure TForm1.Button1Click(Sender: TObject);
var url:string;
response:TStringStream;
error:string;
begin
response:=TStringStream.Create('');
IdHTTP1.IOHandler := IdSSLIOHandlerSocket1;
IdHTTP1.HandleRedirects:=false;
IdSSLIOHandlerSocket1.SSLOptions.Method := sslvSSLv3;
url:='https://passport.jd.com/new/login.aspx';
try
IdHTTP1.Get(url);
except
on E: Exception do
error:=E.Message;
end;
url:= IdHTTP1.Response.Location;
if error='HTTP/1.1 302 Found' then
begin
IdHTTP1.Get(url,response);
Memo1.Text := response.DataString;
end;
response.Free;
end;
需要把下面两个dll和exe放在一起
注意:不要在delphi ide中按F9运行, 这样(try except)异常会被IDE的调试器捕获,当然可以设置忽略异常,把异常传递给程序,不过并不推荐这样做,会影响下次调试。
看效果直接双击exe即可。
std::string 常用函数
string replace(const string & str , const string & src , const string & dest )
{
string ret;
string:: size_type pos_begin = 0;
string:: size_type pos = str.find( src);
while (pos != string::npos)
{
cout << "replacexxx:" << pos_begin <<" " << pos <<"\n";
ret.append( str.data() + pos_begin, pos - pos_begin);
ret += dest;
pos_begin = pos + 1;
pos = str.find( src, pos_begin);
}
if (pos_begin < str.length())
{
ret.append( str.begin() + pos_begin, str.end());
}
return ret;
}
int split(const string & str , vector <string >& ret_, string sep = ",")
{
if ( str.empty())
{
return 0;
}
string tmp;
string:: size_type pos_begin = str.find_first_not_of( sep);
string:: size_type comma_pos = 0;
while (pos_begin != string::npos)
{
comma_pos = str.find( sep, pos_begin);
if (comma_pos != string::npos)
{
tmp = str.substr(pos_begin, comma_pos - pos_begin);
pos_begin = comma_pos + sep.length();
}
else
{
tmp = str.substr(pos_begin);
pos_begin = comma_pos;
}
if (!tmp.empty())
{
ret_.push_back(tmp);
tmp = "";
}
}
return 0;
}
string trim(const string & str )
{
string:: size_type pos = str.find_first_not_of( ' ');
if (pos == string::npos)
{
return str;
}
string:: size_type pos2 = str.find_last_not_of( ' ');
if (pos2 != string::npos)
{
return str.substr(pos, pos2 - pos + 1);
}
return str.substr(pos);
}
void MakeSureDirExist(const char * pPath )
{
if ( pPath == NULL)
return;
std:: string strPath( pPath);
if (strPath.at(strPath.length() - 1) != '\\')
strPath += '\\';
int len = strPath.length();
for( int i =0; i < len; ++i)
{
if(strPath[i]== '\\')
{
:: CreateDirectory((strPath.substr(0, i)).c_str(), NULL );
}
}
}
VC为RichTextBox添加右键菜单
private void InitRichTextBoxContextMenu(RichTextBox textBox)
{
//创建剪切子菜单
var cutMenuItem = new MenuItem( "剪切");
cutMenuItem.Click += (sender, eventArgs) => textBox.Cut();
//创建复制子菜单
var copyMenuItem = new MenuItem( "复制");
copyMenuItem.Click += (sender, eventArgs) => textBox.Copy();
//创建粘贴子菜单
var pasteMenuItem = new MenuItem( "粘贴");
pasteMenuItem.Click += (sender, eventArgs) => textBox.Paste();
//创建右键菜单并将子菜单加入到右键菜单中
var contextMenu = new ContextMenu();
contextMenu.MenuItems.Add(cutMenuItem);
contextMenu.MenuItems.Add(copyMenuItem);
contextMenu.MenuItems.Add(pasteMenuItem);
textBox.ContextMenu = contextMenu; //为richtextbox设置菜单
}