Sharepoint 中读取得不同类型SPField 时的处理方式之一

本文介绍了一种从带有特定标记的字符串中提取数据的方法,包括查找特定字符序列以分割和处理字符串,适用于多种字段类型如查找引用或用户输入、计算字段、多选字段和超链接字段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        private string GetDataFromLookUpOrUser(string tempString)
        {
            string temp = "";
            string temp2 = "";
            string temp3 = "";
            string temp4 = "";
            int count = 0;
            Boolean start = true;
            for (int i = 0; i < tempString.Length; i++)
            {
                temp += tempString.Substring(i, 1);
                if (i < tempString.Length - 1)
                {
                    if (tempString.Substring(i, 2) == "#^")
                    {
                        if (start == true)
                        {
                            temp2 = temp.Substring(0, temp.Length - 1);
                            temp = "";
                            i++;
                            start = false;
                        }
                    }
                    else if (tempString.Substring(i, 2) == "^#")
                    {
                        temp3 += temp.Substring(1, temp.Length - 2);
                        temp = "";
                        i++;
                        start = true;
                        count = 0;
                        temp4 += temp2 + temp3;
                        temp3 = "";
                    }
                    else if (tempString.Substring(i, 2) == ";#" && start == false)
                    {
                        count++;
                        if (count % 2 == 0)
                        {
                            temp3 += temp.Substring(1, temp.Length - 2);
                            temp3 = temp3 + ",";
                            temp = "";
                            i++;
                        }
                        else
                        {
                            temp = "";
                        }
                    }
                }
            }
            return temp4 + temp;
        }

        private string GetDataFromCalculatedField(string tempString)
        {
            string temp = "";
            string temp2 = "";
            string temp3 = "";
            string temp4 = "";
            int count = 0;
            Boolean start = true;
            for (int i = 0; i < tempString.Length; i++)
            {
                temp += tempString.Substring(i, 1);
                if (i < tempString.Length - 1)
                {
                    if (tempString.Substring(i, 2) == "#%")
                    {
                        if (start == true)
                        {
                            temp2 = temp.Substring(0, temp.Length - 1);
                            temp = "";
                            i++;
                            start = false;
                        }
                    }
                    else if (tempString.Substring(i, 2) == "%#")
                    {
                        temp3 += temp.Substring(1, temp.Length - 2);
                        temp = "";
                        i++;
                        start = true;
                        count = 0;
                        temp4 += temp2 + temp3;
                        temp3 = "";
                    }
                    else if (tempString.Substring(i, 2) == ";#" && start == false)
                    {
                        count++;
                        if (count % 2 == 0)
                        {
                            temp3 += temp.Substring(1, temp.Length - 2);
                            temp3 = temp3 + ",";
                            temp = "";
                            i++;
                        }
                        else
                        {
                            temp = "";
                        }
                    }
                }
            }
            return temp4 + temp;
        }

        private string GetDataFromMultipleChoice(string tempString)
        {
            string temp = "";
            string temp2 = "";
            string temp3 = "";
            string temp4 = "";
            Boolean start = true;
            for (int i = 0; i < tempString.Length; i++)
            {
                temp += tempString.Substring(i, 1);
                if (i < tempString.Length - 3)
                {
                    if (tempString.Substring(i, 4) == "#*MC")
                    {
                        if (start == true)
                        {
                            temp2 = temp.Substring(0, temp.Length - 1);
                            temp = "";
                            i += 3;
                            start = false;
                        }
                    }
                    else if (tempString.Substring(i, 4) == "MC*#")
                    {
                        temp = "";
                        i += 3;
                        start = true;
                        temp4 += temp2 + temp3.Substring(0, temp3.Length - 1);
                    }
                    else if (tempString.Substring(i, 2) == ";#")
                    {
                        temp3 += temp.Substring(0, temp.Length - 1);
                        temp3 = temp3 + ",";
                        temp = "";
                        i++;
                    }
                }
            }
            return temp4 + temp;
        }

        /// <summary>
        /// 取得 HyperLink 类型的值
        /// </summary>
        /// <param name="strValue"></param>
        /// <returns></returns>
        private string GetDataFromHyperLink(string strValue)
        {
            if (strValue == "")
            {
                return "";
            }

            if (strValue.IndexOf(",") > 0)
            {
                return strValue.Substring(0, strValue.IndexOf(","));
            }
            else
            {
                return strValue;
            }
        }

### 使用 C++ 读取 MATLAB 的 `.m` 文件 为了实现这一目标,通常有两种主要的方法: #### 方法一:通过调用 MATLAB Engine API MATLAB 提供了一个名为 MATLAB Engine API 的接口,允许外部应用程序启动 MATLAB 并执行命令。对于 C++ 来说,可以利用 `engine.h` 头文件来加载并运行 `.m` 文件中的函数。 ```cpp #include "engine.h" #include <iostream> int main() { // 启动MATLAB引擎 Engine *ep; if (!(ep = engOpen(""))) { std::cerr << "无法连接到MATLAB引擎\n"; return EXIT_FAILURE; } // 将工作目录设置为包含.m文件的位置 engEvalString(ep, "cd('path_to_your_m_file_directory');"); // 调用.m文件内的函数 engEvalString(ep, "addpath(genpath('path_to_additional_toolboxes'));"); double a = 5.0, b = 3.0; mxArray* result; // 假设要调用的是 You 函数 engPutVariable(ep, "a", mxCreateDoubleScalar(a)); engPutVariable(ep, "b", mxCreateDoubleScalar(b)); engPutVariable(ep, "flag", mxCreateLogicalScalar(0)); engEvalString(ep, "[r,h] = You(a,b,flag);"); // 获取返回的结果 result = engGetVariable(ep, "r"); double output_r = mxGetPr(result)[0]; result = engGetVariable(ep, "h"); double output_h = mxGetPr(result)[0]; std::cout << "Result from MATLAB: r=" << output_r << ", h=" << output_h << "\n"; // 关闭MATLAB引擎 engClose(ep); return EXIT_SUCCESS; } ``` 这种方法依赖于安装有 MATLAB 运行环境,并且需要编译链接特定版本的库文件[^1]。 #### 方法二:将 M 文件转换成共享库 (DLL 或者其他形式) 另一种方式是先将`.m`文件打包成为动态链接库(DLL),之后再由C++程序去调用这个库里的功能。这涉及到创建一个独立的应用程序或组件,它可以在不打开完整的MATLAB界面的情况下被其它语言所使用。具体操作可以通过MATLAB Compiler工具箱完成,在构建过程中会自动生成所需的头文件和导入库[^2]。 这两种方案各有优缺点,前者更灵活但可能性能稍差;后者效率较高却增加了部署复杂度。选择哪种取决于实际应用场景的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值