小编Ser*_*iev的帖子

将URI字符串解析为名称 - 值集合

我有这样的URI:

https://google.com.ua/oauth/authorize?client_id=SS&response_type=code&scope=N_FULL&access_type=offline&redirect_uri=http://localhost/Callback
Run Code Online (Sandbox Code Playgroud)

我需要一个带有解析元素的集合:

NAME               VALUE
------------------------
client_id          SS
response_type      code
scope              N_FULL
access_type        offline
redirect_uri       http://localhost/Callback
Run Code Online (Sandbox Code Playgroud)

确切地说,我需要一个Java等价的C#HttpUtility.ParseQueryString方法.请给我一个建议.谢谢.

java parsing uri namevaluecollection

247
推荐指数
12
解决办法
28万
查看次数

如何手动更改Umbraco中的文档链接

由于与主页的链接不正确,我的面包屑被破坏了.请告诉我,如何手动更改"链接到文档"参数.我使用umbraco 4.7.2我只需要在主页上使用域名,并在内部页面上使用完整的绝对路径.谢谢.

在此输入图像描述

umbraco content-management-system

7
推荐指数
1
解决办法
1万
查看次数

使用C++中的参数将std :: string转换为现有函数

MyFunc(int, double, string)我的项目中有一个已实现的功能.例如,如何使用具有其字符串表示的必要参数来调用此函数

std::string str = "MyFunc(2, 3.12, \"Lemon Juice\")";
Run Code Online (Sandbox Code Playgroud)

并且怎么样的标准功能,例如,我怎么能调用time()std::string "time()"


好的,这是更详细的任务.我有一个map <string, Data> Data包含许多孩子的类包装器.当我调用Data.GetValue()方法时,它返回一个std::string,取决于子类内部数据.其中一个子项Data必须返回int另一个字符串表示形式 - 字符串表示形式double,最后一个 - 当前日期和时间的字符串表示形式.这是问题 - 我不知道如何调用标准函数ctime()来获取其中一个Data孩子的信息.

c++ function

5
推荐指数
1
解决办法
604
查看次数

Windows Forms TextBox Bug?

我有Windows Forms项目.表单上有一个textBox,名为txt.任务是在两列中的textBox解析文本中编写用户的字符串.每列必须具有左侧对齐.这是一个例子:

--------------------------
Parameters          Values

height              36
width               72
length of trousers  32
--------------------------
Run Code Online (Sandbox Code Playgroud)

每个值都必须在另一个之下.显然,我们需要一个方法,在每个参数之后输入必要数量的空格.我开发了这个方法:

private string AddSpaces(string str)
{
    const int MAX_WIDTH = 50;
    // We've got a 50 symbols field to fill it with current parameter
    // name and add necessary number of spaces.

    StringBuilder strWithSpaces = new StringBuilder();
    int numOfSpaces = MAX_WIDTH - str.Length;
        for (int i = 0; i < numOfSpaces; i++)
        {
            strWithSpaces.Append(" ");
        }
        return strWithSpaces.ToString();
}
Run Code Online (Sandbox Code Playgroud)

我使用以下字符串测试了此方法:

string report = Environment.NewLine + "-------------" …
Run Code Online (Sandbox Code Playgroud)

c# textbox winforms

4
推荐指数
1
解决办法
881
查看次数

函数中的参数数量未知

我有班级成员:

LineND::LineND(double a ...)
{
    coefficients.push_back(a);
    va_list arguments;
    va_start(arguments, a);
    double argValue;
    do
    {
        argValue = va_arg(arguments, double);
        coefficients.push_back(argValue);
    }while(argValue != NULL);   // THIS IS A PROBLEM POINT!
    va_end(arguments);
}
Run Code Online (Sandbox Code Playgroud)

我不知道将使用多少个参数.我需要将每个参数都放入调用的向量中coefficients.我该怎么办?我理解,while(argValue != NULL)在这种情况下声明不正确.我不能使用例如这个签名:

LineND::LineND(int numArgs, double a ...)
Run Code Online (Sandbox Code Playgroud)

改变这样的条件:

while(argValue != numArgs);
Run Code Online (Sandbox Code Playgroud)

关键是我无法改变方法的签名.需要另一种方法来解决这个问题.

c++ variadic-functions argument-passing

3
推荐指数
1
解决办法
9501
查看次数

使用 JSON.net 库 (C#) 替换 JSON 字符串中的值

我有一个 JSON 字符串。我需要替换其中的一些值。我这样做:

string jsonString = "{\"id\": \"5281959998_126883980715630\", \"name\": \"The New York Times\", \"category\": \"Company\"}";
JObject jObj = JObject.Parse(jsonString);
jObj["category"] = "inc";
string strJson = jObj.ToString();
Run Code Online (Sandbox Code Playgroud)

但它不能正常工作!符号“\r\n”出现在每个键值对之后。我究竟做错了什么?如何防止出现这些符号?

c# json.net

3
推荐指数
1
解决办法
7372
查看次数

重构仅由一个函数调用不同的代码块

我有类似的公式来计算哈特利变换.唯一的区别是输入函数 - sin,cos,exp在以下代码行中:

Math.Exp((double)tau)
Math.Sin((double)tau)
Math.Cos((double)tau)
Run Code Online (Sandbox Code Playgroud)

如何在以下片段中逃避几乎相同的代码片段并缩短我的代码?

 private void CountHartley(ref double [] arr, string function)
        {
            int N = arr.Length;
            if (function == "exp")
            {
                for (int nu = 0, tau = 0; ((nu < N) && (tau < N)); nu++, tau++)
                {
                    arr[nu] = 1 / (double)N *
                                 Math.Exp((double)tau) *
                                 (Math.Sin(2 * Math.PI * nu * tau / (double) N) +
                                 Math.Cos(2 * Math.PI * nu * tau / (double) N));
                }
            }
            else if (function == "sin")
            { …
Run Code Online (Sandbox Code Playgroud)

c# code-reuse

2
推荐指数
1
解决办法
151
查看次数

在HttpConfiguration实例中的ASP.NET Web API应用程序中处理json pretty print param

我需要在ASP.NET Web API应用程序中添加和处理可选的"漂亮"参数.当用户发送"pretty = true"时,应用程序响应应该看起来像带有缩进的人类可读的json.当用户发送"pretty = false"或根本不发送此参数时,他必须得到没有空格符号的json作为响应.

这就是我所拥有的: Global.asax.cs

public class WebApiApplication
        : HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        }
    }
Run Code Online (Sandbox Code Playgroud)

WebApiConfig.cs

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Filters.Add(new ValidateModelAttribute());
            config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting = Newtonsoft.Json.Formatting.Indented
            };
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
...
Run Code Online (Sandbox Code Playgroud)

如您所知,我需要在Register方法中使用这样的逻辑:

config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting = Newtonsoft.Json.Formatting.Indented
            };
if(prettyPrint) // must be extracted from request and passed here somehow
{ …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc json pretty-print json.net asp.net-web-api

2
推荐指数
1
解决办法
1636
查看次数

在Excel中将数据从Excel工作簿读取到ArrayList时性能低下

这是一个问题描述.

条件:一般的想法是从MS Excel文件中读取大量实数,并将它们放入inro ArrayList中进行进一步处理.excel工作簿只有一个工作表.所有数字都是实数,它们存储在一列中.我逐行读取这些数字并将它们放入ArrayList中.

问题:这个过程花费了太多时间.程序花费大约2分钟来填充具有10000个元素的ArrayList.这是我的代码.我需要你的建议让它更快.但是文件的结构无法修改.它只能修改代码.请帮助我加快速度.

// Method GetExcelData opens 1 excel file, reads data row by row and adds
// it into the array of source Data Values (sourceDataValues in our case).
private void GetExcelData(string fullPath, ArrayList arrForValues)
{
    Excel.Application excelapp = new Excel.Application();
    excelapp.Visible = false;
    // to avoid appearing of Excel window on the screen
    Excel.Workbook excelappworkbook = excelapp.Workbooks.Open(
        fullPath,
        Type.Missing, Type.Missing, true, Type.Missing,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing,
        Type.Missing, Type.Missing);
    Excel.Worksheet excelworksheet = (Excel.Worksheet)excelappworkbook.Worksheets.get_Item(1); …
Run Code Online (Sandbox Code Playgroud)

c# excel

1
推荐指数
1
解决办法
5203
查看次数

无法在二叉树中实现递归搜索

这是我的代码:

  template <typename DataType> bool SearchValue(TreeNode<DataType> *root, DataType search_value)
{
    if(search_value != root->data)
    {
        if(root->right != NULL)
        {
            return SearchValue(root->right, search_value);
        }
        if (root->left != NULL)
        {
            return SearchValue(root->left, search_value);
        }
        return false;
    }
    else
    {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

我无法使SearchValue功能正常工作.条件不是改变SearchValue功能的签名.问题如下:例如,我们尝试找到数据字段等于"90"的元素,它存在于树中.有时这段代码会找到这个元素,有时候不会 - 取决于它在树中的位置.问题是如何使其每次都正常工作.

我以这种方式构建树:

template <typename DataType> TreeNode<DataType> *BuildTree()
{
    TreeNode<DataType> *root = new TreeNode<DataType>(10, new TreeNode<DataType>(20), new TreeNode<DataType>(30));

    TreeNode<DataType> *curRoot = root;
    curRoot = curRoot->left;
    curRoot->left = new TreeNode<DataType>(40);
    curRoot->left->left = new TreeNode<DataType>(70);
    curRoot->right = …
Run Code Online (Sandbox Code Playgroud)

c++ recursion binary-tree

0
推荐指数
1
解决办法
189
查看次数