小编SLe*_*ner的帖子

处理angularUI路由器中的尾部斜杠

自从我开始研究这个问题已经有好几个小时了,我似乎无法理解解决方案.

我有一个应用程序,可能会导致用户实际输入URL.在这种情况下,不难相信用户可能会输入尾部斜杠.例如,

www.example.com/users/2和www.example.com/edit/company/123

应该像对待一样对待

www.example.com/users/2/和www.example.com/edit/company/123/

这只需要在客户端处理URL路由.我对处理资源/ API调用中的尾部斜杠不感兴趣.我只对处理浏览器中的尾随处理感兴趣.

所以我研究并发现网上的答案不多.他们中的大多数人都把我带到了angular-ui路由器的FAQ部分.

https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions

在这里,他们告诉我们写一条规则,这是我想要做的,但它似乎没有起作用,或者我做错了.

这是我添加代码的plunkr.

http://plnkr.co/edit/fD9q7L?p=preview

我已将此添加到我的配置中,其余代码几乎是基本的东西.

$urlRouterProvider.rule(function($injector, $location) {
  //if last charcter is a slash, return the same url without the slash
  if($location.$$url[length-1] === '/') {
    return $location.$$url.substr(0,$location.$$url.length - 2);
  } else {
    //if the last char is not a trailing slash, do nothing
    return $location.$$url;
  }
});
Run Code Online (Sandbox Code Playgroud)

基本上,我想使尾随斜杠可选,即它在地址栏上的存在与否应该对加载的状态没有影响.

angularjs angular-ui angular-routing angular-ui-router

33
推荐指数
3
解决办法
2万
查看次数

如何避免在try-catch块中定义的"未分配的局部变量"

这是我经常遇到的一个错误.虽然我设法以某种方式规避它,但它真的让我烦恼.在下面的代码片段中,我想要安全防范来自myRequest.GetResponse()的异常

        WebRequest myRequest = WebRequest.Create(baseUri.OriginalString);
        WebResponse myResponse;
        Stream myStream;
        StreamReader reader;
        try
        {
            myResponse = myRequest.GetResponse();
            myStream = myResponse.GetResponseStream();
            reader = new StreamReader(myStream);
        }
        catch (WebException status)
        {
            txtConsole.AppendText("Error in GetLinks::WebException\n" + status.Response);
            txtConsole.AppendText(Environment.NewLine);
        }
        catch
        {
            txtConsole.AppendText("Some error in GetLinks");
            txtConsole.AppendText(Environment.NewLine);
        }

        Regex regex = new Regex(@"\s*(?i)href\s*=\s*(\""([^""]*\"")|'[^']*'|([^'"">\s]+))", RegexOptions.IgnoreCase);
        MatchCollection splits = regex.Matches(reader.ReadToEnd());
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试构建/编译代码时,它说

"使用未分配的局部变量'读者'"

现在我的问题是,如果try语句运行顺利而没有抛出任何异常,为什么编译器不能访问try块内分配给reader的值?

c# exception-handling try-catch

8
推荐指数
2
解决办法
8062
查看次数

如何定义指向结构的指针

我知道这是一个非常基本的问题,但如果没有它我就无法前进,而且其他地方也没有明确解释.

为什么这个编程给了我很多未声明的标识符错误?不过我已经宣布了.

这些是我得到的错误.

Error   2   error C2143: syntax error : missing ';' before 'type'
Error   3   error C2065: 'ptr' : undeclared identifier
Error   4   error C2065: 'contactInfo' : undeclared identifier
Error   5   error C2059: syntax error : ')'
Error   15  error C2223: left of '->number' must point to struct/union
Run Code Online (Sandbox Code Playgroud)

和更多...

#include<stdio.h>
#include<stdlib.h>

typedef struct contactInfo
{
    int number;
    char id;
}ContactInfo;


void main()
{

    char ch;
    printf("Do you want to dynamically etc");
    scanf("%c",&ch);
    fflush(stdin);


        struct contactInfo nom,*ptr;
        ptr=(contactInfo*)malloc(2*sizeof(contactInfo));

    nom.id='c';
    nom.number=12; …
Run Code Online (Sandbox Code Playgroud)

c pointers structure

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

使用c#写入现有Excel文件

我试图打开(或创建一个新的xls)Excel文件并为其写一些值.虽然,如果我只是创建一个新的xls文件,下面的程序工作得很好,我遇到了一些问题

**mWorkBook = oXL.Workbooks.Open (path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);**
Run Code Online (Sandbox Code Playgroud)

这是错误:无法访问"LOG.xls".该文件可能已损坏,位于未响应的服务器上,或者只读.它不是只读的,它没有被破坏(因为有时文件是在运行时创建的).那有什么问题呢?

private static Microsoft.Office.Interop.Excel.Workbook mWorkBook;
    private static Microsoft.Office.Interop.Excel.Sheets mWorkSheets;
    private static Microsoft.Office.Interop.Excel.Worksheet mWSheet1;
    private static Microsoft.Office.Interop.Excel.Application oXL;

    private void btnSignIn_Click ( object sender, EventArgs e )
    {

        string path = "D:\\LOG.xls";
        if(!File.Exists(path))
        {
            File.Create (path);
        }


        oXL = new Microsoft.Office.Interop.Excel.Application ();
        oXL.Visible = true;
        oXL.DisplayAlerts = false;
        //error on this line
        mWorkBook = oXL.Workbooks.Open (path, 0, false, 5, "", "", false, …
Run Code Online (Sandbox Code Playgroud)

c# interop office-interop excel-interop

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

C++ Basic中的类模板

template<class T>
class Stack 
{
public:
    Stack()
    {
        cout<<"Enter size\n";
        cin>>size;
        //stackPtr=new int[size];
        stackPtr= new T[size];
        top =0;
    }

    ~Stack()
    {
        delete[] stackPtr;
    }

    void display()
    {
        cout<<"*****************************\n";
        for(int i=0;i<top;i++)
            cout<<stackPtr[i]<<endl;
        cout<<"*****************************\n";
    }

    bool Push()
    {
        int a;
        cout<<"Enter element\n";
        cin>>a;
        if(isFull()==false)
        {
            stackPtr[top++]=a;
            return true;
        }
        else
            return false;
    }

    bool Pop()
    {
        if(isEmpty()==false)
        {   
            top--;
            return true;
        }
        else 
            return false;
    }

    bool isEmpty()
    {
        if(top==0)
            return true;
        else
            return false;
    }

    bool isFull()
    {
        if(top==size)
            return true; …
Run Code Online (Sandbox Code Playgroud)

c++ templates undeclared-identifier

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