求和3个数组(字符串)中的所有项目

时间:2015-11-04 12:29:37

标签: vbscript

我有3个字符串,我希望按月分享点对点项目。

    Parse.enableLocalDatastore(this);
    Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_ID);
    ParseFacebookUtils.initialize(this);

    ParsePush.subscribeInBackground("global", new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {

            }
        }
    });
ParseInstallation currentInstallation =         ParseInstallation.getCurrentInstallation();
    currentInstallation.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {

            }
        }
    });

以下结果:

string1 = "201402,10|201403,15|201404,25|201405,11|201406,23"
string2 = "201401,17|201402,25|201403,15|201404,12|201405,13|201406,9"
string3 = "201405,17|201406,25|201407,15|201408,12|201409,13|201410,9|201411,9|201412,9|201501,9"

1 个答案:

答案 0 :(得分:0)

在管道中拆分每个字符串,用逗号分隔每个子字符串,然后使用字典累积每年和每月的值。这样的事情应该有效:

string1 = "201402,10|201403,15|201404,25|201405,11|201406,23"
string2 = "201401,17|201402,25|201403,15|201404,12|201405,13|201406,9"
string3 = "201405,17|201406,25|201407,15|201408,12|201409,13|201410,9|201411,9|201412,9|201501,9"

Set d = CreateObject("Scripting.Dictionary")

Sub Add(s)
  For Each line In Split(s, "|")
    v = Split(line, ",")
    d(v(0)) = d(v(0)) + CInt(v(1))
  Next
End Sub

Add string1
Add string2
Add string3

Set a = CreateObject("System.Collections.ArrayList")
For Each key In d.Keys
  a.Add key & "," & d(key)
Next
a.Sort
result = Join(a.ToArray, "|")

WScript.Echo result