0

HI all i am Building A string Which looks like this

 [Anil Kumar K,Niharika,Raghu,/4,0,0,/3,0,0,/1,1,1,/1,0,0,]

i am building this string with this data

public JsonResult ResourceBugReports()
    {
        int projectid;
        int Releasphaseid;
        projectid = 16;
        Releasphaseid = 1;
        var ResourceReports = db.ExecuteStoreQuery<ResourceModel>("ResourceBugReports @ProjectId,@ReleasePhaseId", new SqlParameter("@ProjectId", projectid), new SqlParameter("@ReleasePhaseId", Releasphaseid)).ToList();
        DataSet ds = new DataSet();        

        var model1 = new WeeklyBugCount
        {
            Resources = ResourceReports
        };
        foreach (var row in model1.Resources)
        {
            ResourceName1 = ResourceName1 + row.EmployeeName + ",";
        }
        foreach (var row in model1.Resources)
        {
            BugsCount = BugsCount + row.Assignedbugs + ",";
        }
        foreach (var row in model1.Resources)
        {
            BugsCount1 = BugsCount1+ row.Closedbugs + ",";
        }
        foreach (var row in model1.Resources)
        {
            Bugscount2 = Bugscount2 + row.Fixedbugs + "," ;
        }
        foreach (var row in model1.Resources)
        {
            BugsCount3 = BugsCount3 + row.Reopenedbugs + ",";
        }

        ComboinedString = ResourceName1 + "/" + BugsCount + "/" + BugsCount1 + "/" + Bugscount2 + "/" + BugsCount3;

        return Json(ComboinedString, JsonRequestBehavior.AllowGet);
    }

my

ComboinedString =[Anil Kumar K,Niharika,Raghu,/4,0,0,/3,0,0,/1,1,1,/1,0,0,]

but i want this string

 ComboinedString =[Anil Kumar K,Niharika,Raghu/4,0,0/3,0,0,/1,1,1/1,0,0]

i want to remove this "," before the "/" in this strin or replace it..can any one help me

4 Answers 4

1

Add this statement

I hope it will help you

String CombinedString1 = CombinedString.Replace(",/", "/");
Sign up to request clarification or add additional context in comments.

Comments

1

A simple solution is a search and replace on the string replacing ",/" with "/".

A better solution is, rather than using a for() loop and appending a comma at the end of each value, is use String.Join(). For example, replace:

    foreach (var row in model1.Resources)
    {
        ResourceName1 = ResourceName1 + row.EmployeeName + ",";
    }

with

    ResourceName1 = string.Join(",", model1.Resources.ToArray())

This will remove the trailing comma.

Comments

0

A simple solution would be to use String.EndsWith() function i.e.

string str = "ksjf,sjsfj,sfs,";
        if (str.EndsWith(","))
        {
            str = str.Remove(str.Length - 1);

        }

Comments

0

Off the top of my head, you could try to replace with a simple regular expression:

string input = "dsgd,sdgsdg,dsgsdg,sdg,";
string output = Regex.Replace(input, ",$", "");
//output: "dsgd,sdgsdg,dsgsdg,sdg"

@user1542652's solution is simple and works just as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.