Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:23:09+00:00 2026-06-14T17:23:09+00:00

I have this string: var result = / 07-09-2012 73 ABC / 11-09-2012 195

  • 0

I have this string:

var result = " / 07-09-2012 73 ABC / 11-09-2012 195 DEF/ 03-09-2012 95 / 04-09-2012 188 ABC / 31-10-2012 72 / 18-09-2012 205 / 26-09-2012 244 ABC / 14-09-2012 86 / 20-09-2012 92 DEF / 28-09-2012 97 / 01-09-2012 95 DEF/ 17-09-2012 95 / 17-09-2012 83 / 12-09-2012 95 / 18-09-2012 95 ABC / 18-09-2012 69 / 21-09-2012 95 / 21-09-2012 95 ABC/ 24-09-2012 144 / 28-09-2012 93 DEF";

The string is divided in 3 categories.

  1. Date (dd/mm/yyyy)
  2. Number
  3. Character

thus: 07-09-2012 73 ABC

I want to get the sum of number, where date is 09 and has character ABC.

Currently, from another question I found out how to retrieve just the date, when string has no characters
Example: http://jsfiddle.net/javascript/pBNNt/10/

var result = " / 07-09-2012 73 / 11-09-2012 195 / 03-09-2012 95 / 04-09-2012 188 / 31-10-2012 72 / 18-09-2012 205 / 26-09-2012 244 / 14-09-2012 86 / 20-09-2012 92 / 28-09-2012 97 / 01-09-2012 95 / 17-09-2012 95 / 17-09-2012 83 / 12-09-2012 95 / 18-09-2012 95 / 18-09-2012 69 / 21-09-2012 95 / 21-09-2012 95 / 24-09-2012 144 / 28-09-2012 93";

var resultArr = result.split('/');
var results = {}; //sum by month
for (var i = 0; i < resultArr.length; i++) {    
    if ( resultArr[i].length >= 11) { //it has date
        var resultTkn = resultArr[i].split(' ');

        if (resultTkn[1].length == 10) { //it is a date
            var date = resultTkn[1].split('-');
            var sum = 0;
            if (results.hasOwnProperty(date[1])) {
                sum = results[date[1]];
            }

            sum += parseFloat(resultTkn[2]);
            results[date[1]] = sum;
        }
    }
}
$('div').text(results["09"])

​

Now how can I do the same, but retrieve the sum of a specific date or month, with the specific character.

Here is my current fiddle with the string: http://jsfiddle.net/javascript/pBNNt/8/

Something like: results["09/2012,ABC"]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:23:10+00:00Added an answer on June 14, 2026 at 5:23 pm

    How about that:

    function search(result, cat) {
        var data = [],
            lines = result.split(/\s*\/\s*/);
        for (var i = 0; i < lines.length; i++) {
            if (lines[i] === "") continue;
            var s = lines[i].split(/\s+/);
            data.push({
                date: s[0],
                number: parseInt(s[1], 10) || 0,
                char: s[2] || ""
            });
        }
    
        var num = 0;
        for (var j = 0; j < data.length; j++) {
            if ((cat.char && data[j].char === cat.char) &&
                (cat.date && data[j].date.indexOf(cat.date) !== -1)) {
                num += data[j].number;
            }
        }
        return num;
    }
    
    var result = " / 07-09-2012 73 ABC / 11-09-2012 195 DEF/ 03-09-2012 95 / 04-09-2012 188 ABC / 31-10-2012 72 / 18-09-2012 205 / 26-09-2012 244 ABC / 14-09-2012 86 / 20-09-2012 92 DEF / 28-09-2012 97 / 01-09-2012 95 DEF/ 17-09-2012 95 / 17-09-2012 83 / 12-09-2012 95 / 18-09-2012 95 ABC / 18-09-2012 69 / 21-09-2012 95 / 21-09-2012 95 ABC/ 24-09-2012 144 / 28-09-2012 93 DEF";
    
    var total = search(result, {
        char: "ABC",
        date: "-09-2012"
    });
    
    console.log(total);
    

    DEMO: http://jsfiddle.net/pBNNt/12/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string: var someString = 23/03/2012; and want to replace all the
I have this in AS3 var myName:String = David; var result:Number = ExternalInterface.call(methodInJS, myName);
Let's say I have this string var: string strData = 1|2|3|4||a|b|c|d Then, I make
Let's say for an instance I have this string: var a=23434,bc=3434,erd=5656,ddfeto='dsf3df34dff3',eof='sdfwerwer34',wer=4554; How should I
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
I have this in HomeController : public ActionResult Details(string id) { var customer =
I have a string like this: var string = ' [United States] [Canada] [India]
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
I have an ordered list like this: var list = new List<String>(){aaa,aab,aac,baa,bab,bac}; I want
I have a string contaning some html markup, like this: var html = <div>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.