2014年9月25日 星期四

C++ 字串切割

Arguments AnalyticArguments(int argc, _TCHAR* argv[])
{
    //初始化
    Arguments args;
    args.strAction = "";
    args.strVMName = "";
    args.strSnapshotName = "";

    if(argc >= 3)
    {
        //歷遍所有參數
        for(int i=0 ; i -1)
        {
            //取得一個參數 ex:/Action=start
            string strArgument = argv[i];
            //初始化
            int iTok = -1;
            //=========================判斷參數keyword=========================
            if((iTok = strArgument.find("/Action")) > -1)
            {
                iTok = strArgument.find("=");
                int strLength = strArgument.length();
                //判斷等號右邊是否有文字
                if(iTok > -1)
                    args.strAction = strArgument.substr(iTok+1, strLength);
            }
            else if((iTok = strArgument.find("/VMName")) > -1)
            {
                iTok = strArgument.find("=");
                int strLength = strArgument.length();
                //判斷等號右邊是否有文字
                if(iTok > -1)
                    args.strVMName = strArgument.substr(iTok+1, strLength);
            }
            else if((iTok = strArgument.find("/SnapshotName")) > -1)
            {
                iTok = strArgument.find("=");
                int strLength = strArgument.length();
                //判斷等號右邊是否有文字
                if(iTok > -1)
                    args.strSnapshotName = strArgument.substr(iTok+1, strLength);
            }
            //=================================================================
        }
    }
    return args;
}

C++ 讀文字檔

list lisVMNames;
char line[100];
fstream fin;
//讀檔
fin.open("D:\\Joyce\\TXTs\\BigFarmer.txt",ios::in);
while(fin.getline(line,sizeof(line),'\n'))
{
    //將一行文字存入list
    lisVMNames.push_back(line);
}

2014年9月22日 星期一

C# 字串切割

string[] strParameter = args[i].Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);

以範例來說,以等號切割字串後,由字串陣列接收

關鍵字可用string,而不僅限於char

2014年9月9日 星期二

C# 列出目錄及子目錄之所有檔案或特定檔案

轉貼自:http://note.tc.edu.tw/446.html
C# 列出目錄及子目錄之所有檔案

用遞迴的方法,列出目錄及子目錄之所有檔案。以下的方法如果目錄或檔名太長會出錯。
using System.IO;
using System.Collections;

private void GetFiles(DirectoryInfo di, string searchPattern, ref ArrayList MyFiles)
{
     //取得檔案
    foreach (FileInfo fi in di.GetFiles(searchPattern))
    {
        MyFiles.Add(fi.FullName);
    }

    // Search in subdirctories
    foreach (DirectoryInfo d in di.GetDirectories())
    {
        GetFiles(d, searchPattern, ref MyFiles); //遞迴方法
    }
}

VisualStudio 2012 CrystalReport 無法載入crdb_adoplus.dll

轉貼來自:
http://fms-dot-net-notes.blogspot.tw/2011/09/crystalreport2010-crdbadoplusdll.html

在VS2012中使用CrystalReport 會出現一個錯誤
發生"無法載入檔案或組件’file:///C:\Program Files\SAP BusinessObject\Crystal Report for .Net Framework 4.0\Common\SAP BusinessObject Enterprise XI 4.0\win32_x86\donet1\crdb_adoplus.dll’或其相依性的其中之一系統找不到指定的檔案"
奇怪的是,裝好CrystalReport後卻沒有 donet1 這個資料匣!!
crdb_adoplus.dll 這個檔案卻是在 win32_x86 這個資料匣下...... XD

解決方式就是在 C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86 目錄下新增一個資料匣 dotnet1
再把 crdb_adoplus.dll 複製過去

好........
執行後就會發現又出現了另一個錯誤~~
混合模式組件是針對版本 ‘v2.0.50727′ 的執行階段建置的,無法在沒有其他組態資訊的情況下載入 4.0 執行階段中。

解決方式~
如果是 Web 就開啟 web.config 如果是 WinForm 就開啟 app.conifg
找到
< startup >
    < supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" / >
< /startup >

並在 startup 加上 useLegacyV2RuntimeActivationPolicy="true"

< startup useLegacyV2RuntimeActivationPolicy="true" >
    < supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" / >
< /startup >

2014年9月4日 星期四

C++ Command Line 傳入參數方法

#include < iostream >

using namespace std;  
  
int main(int argc,char **argv){  
  
    for(int i=0;i < argc ; i++)  
        cout << "Argument " << i << " is " << argv[i] << endl;  
    return EXIT_SUCCESS;  
}  

當透過Dos模式呼叫test.exe時,如果需要傳入參數,可傳入以下指令

test.exe hello! this is a test!

結果如下: