Reading 'CSV' file - Not displayed loong string - ios

My friends, I have an issue that I hope you can help me.
Here is a similar problem, but it is also not solved:
Reading 'CSV' file - Cannot read csv file contains loong string
So...Here is my code:
NSString* filePath = [[NSBundle mainBundle] pathForResource:#"nameorg" ofType:#"csv"];
NSString* fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSWindowsCP1251StringEncoding error:nil];
NSMutableArray* pointStrings = [[NSMutableArray alloc] initWithArray:[fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]];
for(int idx = 0; idx < [pointStrings count]; idx++)
{
NSString *currentPointString = [pointStrings objectAtIndex:idx];
if ([currentPointString length] == 0) {
continue;
}
NSMutableArray *arr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#";"]];
if ([arr count] < 5) {
continue;
}
NSLog(#"1: %#; 2: %#; 3: %#; 4: %#; 5: %#;", [arr objectAtIndex:0], [arr objectAtIndex:1], [arr objectAtIndex:2], [arr objectAtIndex:3], [arr objectAtIndex:4]);
}
My csv file:
2.6.;¬ качестве адреса организации можно использовать адрес офиса учредител€, в том числе домашний адрес руководител€ фирмы, адрес арендованного помещени€.;;The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.;
2.7.;Ёлектронна€ подача с помощью сервиса Ђѕодача электронных документов на государственную регистрациюї http://www.nalog.ru/el_usl/gosreg_eldocs/;"1. «аполнить в интерактивном режиме за€вление и направить его в налоговую инспекцию.
2. ѕодготовить полный пакет документов в электронном виде и направить его в налоговый орган.";E-applications submission through the service ЂElectronic submission of documents for state registrationї†http://www.nalog.ru/el_usl/gosreg_eldocs/;"1 . To fill an application online and submit it to tax service.
2 . To prepare a full set of documents in electronic form and send it to tax registration authority."
2.8.;¬ бумажном виде;;In paper form;
The problem: Not displayed item 2.7. Why?
My NSLog:
2014-02-11 14:03:34.139 CSVSQLITE[4127:70b] 1: 2.6.; 2: В качестве адреса организации можно использовать адрес офиса учредителя, в том числе домашний адрес руководителя фирмы, адрес арендованного помещения.; 3: ; 4: The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.; 5: ;
2014-02-11 14:03:34.163 CSVSQLITE[4127:70b] 1: 2.8.; 2: В бумажном виде; 3: ; 4: In paper form; 5: ;
Thanks so much in advanced.
output of pointStrings:
(
"2.6.;\U0412 \U043a\U0430\U0447\U0435\U0441\U0442\U0432\U0435 \U0430\U0434\U0440\U0435\U0441\U0430 \U043e\U0440\U0433\U0430\U043d\U0438\U0437\U0430\U0446\U0438\U0438 \U043c\U043e\U0436\U043d\U043e \U0438\U0441\U043f\U043e\U043b\U044c\U0437\U043e\U0432\U0430\U0442\U044c \U0430\U0434\U0440\U0435\U0441 \U043e\U0444\U0438\U0441\U0430 \U0443\U0447\U0440\U0435\U0434\U0438\U0442\U0435\U043b\U044f, \U0432 \U0442\U043e\U043c \U0447\U0438\U0441\U043b\U0435 \U0434\U043e\U043c\U0430\U0448\U043d\U0438\U0439 \U0430\U0434\U0440\U0435\U0441 \U0440\U0443\U043a\U043e\U0432\U043e\U0434\U0438\U0442\U0435\U043b\U044f \U0444\U0438\U0440\U043c\U044b, \U0430\U0434\U0440\U0435\U0441 \U0430\U0440\U0435\U043d\U0434\U043e\U0432\U0430\U043d\U043d\U043e\U0433\U043e \U043f\U043e\U043c\U0435\U0449\U0435\U043d\U0438\U044f.;;The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.;",
"",
"2.7.;\U042d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U0430\U044f \U043f\U043e\U0434\U0430\U0447\U0430 \U0441 \U043f\U043e\U043c\U043e\U0449\U044c\U044e \U0441\U0435\U0440\U0432\U0438\U0441\U0430 \U00ab\U041f\U043e\U0434\U0430\U0447\U0430 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U044b\U0445 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U043d\U0430 \U0433\U043e\U0441\U0443\U0434\U0430\U0440\U0441\U0442\U0432\U0435\U043d\U043d\U0443\U044e \U0440\U0435\U0433\U0438\U0441\U0442\U0440\U0430\U0446\U0438\U044e\U00bb http://www.nalog.ru/el_usl/gosreg_eldocs/;\"1. \U0417\U0430\U043f\U043e\U043b\U043d\U0438\U0442\U044c \U0432 \U0438\U043d\U0442\U0435\U0440\U0430\U043a\U0442\U0438\U0432\U043d\U043e\U043c \U0440\U0435\U0436\U0438\U043c\U0435 \U0437\U0430\U044f\U0432\U043b\U0435\U043d\U0438\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U0443\U044e \U0438\U043d\U0441\U043f\U0435\U043a\U0446\U0438\U044e.",
"2. \U041f\U043e\U0434\U0433\U043e\U0442\U043e\U0432\U0438\U0442\U044c \U043f\U043e\U043b\U043d\U044b\U0439 \U043f\U0430\U043a\U0435\U0442 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U0432 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U043e\U043c \U0432\U0438\U0434\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U044b\U0439 \U043e\U0440\U0433\U0430\U043d.\";E-applications submission through the service \U00abElectronic submission of documents for state registration\U00bb\U00a0http://www.nalog.ru/el_usl/gosreg_eldocs/;\"1 . To fill an application online and submit it to tax service.",
"",
"2 . To prepare a full set of documents in electronic form and send it to tax registration authority.\"",
"",
"2.8.;\U0412 \U0431\U0443\U043c\U0430\U0436\U043d\U043e\U043c \U0432\U0438\U0434\U0435;;In paper form;",
"",
)
output of arr:
2014-02-11 14:07:58.545 CSVSQLITE[4249:70b] arr: (
"2.6.",
"\U0412 \U043a\U0430\U0447\U0435\U0441\U0442\U0432\U0435 \U0430\U0434\U0440\U0435\U0441\U0430 \U043e\U0440\U0433\U0430\U043d\U0438\U0437\U0430\U0446\U0438\U0438 \U043c\U043e\U0436\U043d\U043e \U0438\U0441\U043f\U043e\U043b\U044c\U0437\U043e\U0432\U0430\U0442\U044c \U0430\U0434\U0440\U0435\U0441 \U043e\U0444\U0438\U0441\U0430 \U0443\U0447\U0440\U0435\U0434\U0438\U0442\U0435\U043b\U044f, \U0432 \U0442\U043e\U043c \U0447\U0438\U0441\U043b\U0435 \U0434\U043e\U043c\U0430\U0448\U043d\U0438\U0439 \U0430\U0434\U0440\U0435\U0441 \U0440\U0443\U043a\U043e\U0432\U043e\U0434\U0438\U0442\U0435\U043b\U044f \U0444\U0438\U0440\U043c\U044b, \U0430\U0434\U0440\U0435\U0441 \U0430\U0440\U0435\U043d\U0434\U043e\U0432\U0430\U043d\U043d\U043e\U0433\U043e \U043f\U043e\U043c\U0435\U0449\U0435\U043d\U0438\U044f.",
"",
"The address of administrative office, including home address of the company administrator, the address of leased premises, may be used as address of the organization.",
""
)
2014-02-11 14:07:58.548 CSVSQLITE[4249:70b] arr: (
"2.7.",
"\U042d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U0430\U044f \U043f\U043e\U0434\U0430\U0447\U0430 \U0441 \U043f\U043e\U043c\U043e\U0449\U044c\U044e \U0441\U0435\U0440\U0432\U0438\U0441\U0430 \U00ab\U041f\U043e\U0434\U0430\U0447\U0430 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U044b\U0445 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U043d\U0430 \U0433\U043e\U0441\U0443\U0434\U0430\U0440\U0441\U0442\U0432\U0435\U043d\U043d\U0443\U044e \U0440\U0435\U0433\U0438\U0441\U0442\U0440\U0430\U0446\U0438\U044e\U00bb http://www.nalog.ru/el_usl/gosreg_eldocs/",
"\"1. \U0417\U0430\U043f\U043e\U043b\U043d\U0438\U0442\U044c \U0432 \U0438\U043d\U0442\U0435\U0440\U0430\U043a\U0442\U0438\U0432\U043d\U043e\U043c \U0440\U0435\U0436\U0438\U043c\U0435 \U0437\U0430\U044f\U0432\U043b\U0435\U043d\U0438\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U0443\U044e \U0438\U043d\U0441\U043f\U0435\U043a\U0446\U0438\U044e."
)
2014-02-11 14:07:58.549 CSVSQLITE[4249:70b] arr: (
"2. \U041f\U043e\U0434\U0433\U043e\U0442\U043e\U0432\U0438\U0442\U044c \U043f\U043e\U043b\U043d\U044b\U0439 \U043f\U0430\U043a\U0435\U0442 \U0434\U043e\U043a\U0443\U043c\U0435\U043d\U0442\U043e\U0432 \U0432 \U044d\U043b\U0435\U043a\U0442\U0440\U043e\U043d\U043d\U043e\U043c \U0432\U0438\U0434\U0435 \U0438 \U043d\U0430\U043f\U0440\U0430\U0432\U0438\U0442\U044c \U0435\U0433\U043e \U0432 \U043d\U0430\U043b\U043e\U0433\U043e\U0432\U044b\U0439 \U043e\U0440\U0433\U0430\U043d.\"",
"E-applications submission through the service \U00abElectronic submission of documents for state registration\U00bb\U00a0http://www.nalog.ru/el_usl/gosreg_eldocs/",
"\"1 . To fill an application online and submit it to tax service."
)
2014-02-11 14:07:58.550 CSVSQLITE[4249:70b] arr: (
"2 . To prepare a full set of documents in electronic form and send it to tax registration authority.\""
)
2014-02-11 14:07:58.551 CSVSQLITE[4249:70b] arr: (
"2.8.",
"\U0412 \U0431\U0443\U043c\U0430\U0436\U043d\U043e\U043c \U0432\U0438\U0434\U0435",
"",
"In paper form",
""
)

2.7 is not displaying because of the following if condition.
if ([arr count] < 5)
{
continue;
}
The 2.7 String contains only two ;
NSMutableArray *arr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#";"]];
It'll contain only 3 objects, so the if condition is satisfied.

Related

How to siimulate thousands of devices in Node-red

I have created a simulation of a device using Node red . Basically the device send UDP packets every second until it receives an acknowledgement. I have done that successfully
The problem is am trying to simulate 10000 of such devices. Hence I would need to automate the device creation/enrollment process. Is there a way I can achieve this in Node-red
The json below shows how one device is supposed to behave. it sends a UDP packet to a server and waits for an ACK . If the ACK is not received within a time period, It resends the packet.
Here is the node-red JSON of one device.
[{"id":"a53cc152.31f27","type":"comment","z":"d51aa60c.64d028","name":"Listener","info":"","x":106,"y":134,"wires":[]},{"id":"a972f44d.eaa9e8","type":"comment","z":"d51aa60c.64d028","name":"Sender","info":"","x":136,"y":332,"wires":[]},{"id":"ff1376ae.e08a58","type":"function","z":"d51aa60c.64d028","name":"stringToBytes ","func":"//var binary = msg.payload.toString(2);\n// 6 because it's zero based count\n//var bit7 = binary.charAt(6);\n//msg.payload = bit7;\n//return msg;\n str=msg.payload\n var ch, st, re = [];\n for (var i = 0; i < str.length; i++ ) {\n ch = str.charCodeAt(i); // get char \n st = []; // set up \"stack\"\n do {\n st.push( ch & 0xFF ); // push byte to stack\n ch = ch >> 8; // shift value down by 1 byte\n } \n while ( ch );\n // add stack contents to result\n // done because chars have \"wrong\" endianness\n re = re.concat( st.reverse() );\n }\n msg.payload=re\n // return an array of bytes\n return msg;\n\n","outputs":1,"noerr":0,"x":566,"y":381,"wires":[["98c6c5a8.aaf1c8"]]},{"id":"85d26758.5ee0f8","type":"function","z":"d51aa60c.64d028","name":"ConfigMessge","func":"msg.payload='830546613660520101010201225A8622475A862247E96665D15684EF030000242D0000000000E308000001FFA94F0A1F00FF0B08000000000000002E50000000000000000000000000000000000000000000000000'\nmsg.ip = '127.0.0.1'\nmsg.port='57920'\nreturn msg;","outputs":1,"noerr":0,"x":353,"y":375,"wires":[["ff1376ae.e08a58"]]},{"id":"c83f781f.ae3428","type":"debug","z":"d51aa60c.64d028","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":919,"y":632,"wires":[]},{"id":"98c6c5a8.aaf1c8","type":"http request","z":"d51aa60c.64d028","name":"ParserAPIRequest","method":"GET","ret":"txt","url":"http:/api","tls":"","x":590,"y":529,"wires":[["eac23a48.b479d8","66759bdf.7fd864"]]},{"id":"4a724471.e5158c","type":"inject","z":"d51aa60c.64d028","name":"TimerTrigger","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":148,"y":377,"wires":[[]]},{"id":"eac23a48.b479d8","type":"http response","z":"d51aa60c.64d028","name":"ParserAPIResponse","statusCode":"200","headers":{"content-type":"application/json"},"x":602,"y":614,"wires":[]},{"id":"66759bdf.7fd864","type":"function","z":"d51aa60c.64d028","name":"CheckForAck?","func":"// Loop function\n\ncontext.loops = context.loops || 0;\nmsg\nif (context.loops!==0)\n{\n\n\ncontext.ACK =0\ncontext.ACK=flow.get('ACK')|| 0;\n//msg.payload=context.ACK\nif(context.ACK === 1 ) \n { \n //\n//return msg;\n return [null, null];\n }\nelse\n{\n // msg.payload='No ACK triggered'+ context.ACK\n context.loops = context.loops + 1\n \n}\n \n \n}\n return [msg, msg];\n","outputs":"2","noerr":0,"x":857,"y":364,"wires":[["faa8c055.7dd7d","f8eb8444.61e8f8","a3286965.3120d8"],[]]},{"id":"a3286965.3120d8","type":"udp out","z":"d51aa60c.64d028","name":"Resend Packet","addr":"127.0.0.1","iface":"","port":"","ipv":"udp4","outport":"13500","base64":false,"multicast":"false","x":1116,"y":230,"wires":[]},{"id":"faa8c055.7dd7d","type":"debug","z":"d51aa60c.64d028","name":"Console.log","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1095,"y":494,"wires":[]},{"id":"f8eb8444.61e8f8","type":"delay","z":"d51aa60c.64d028","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":848,"y":420,"wires":[["66759bdf.7fd864"]]},{"id":"637d9a4c.1182d4","type":"udp in","z":"d51aa60c.64d028","name":"RecieveAck","iface":"","port":"13501","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":173,"y":177,"wires":[["8b85adf3.38d6d"]]},{"id":"8b85adf3.38d6d","type":"switch","z":"d51aa60c.64d028","name":"AssignAck","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"'ACK'","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":384,"y":193,"wires":[["1d63307c.82e67"]]},{"id":"66ffd66c.b3c118","type":"function","z":"d51aa60c.64d028","name":"StoreAckInContext","func":"context.ACK=0\nflow.set('ACK',1);\nmsg.payload=flow.get('ACK')\n\nreturn msg;","outputs":1,"noerr":0,"x":717,"y":178,"wires":[["be667fba.f6701"]]},{"id":"be667fba.f6701","type":"debug","z":"d51aa60c.64d028","name":"Console.log","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":909,"y":155,"wires":[]},{"id":"1d63307c.82e67","type":"change","z":"d51aa60c.64d028","name":"Reset","rules":[{"t":"set","p":"ACK","pt":"flow","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":165,"wires":[["66ffd66c.b3c118"]]},{"id":"68ded0.44db513","type":"status","z":"d51aa60c.64d028","name":"","scope":["66759bdf.7fd864"],"x":667,"y":282,"wires":[["a3286965.3120d8"]]}]

How to get the full creadit number form paypalhere SDK named "ios-here-sdk-dist-master", I am getting "maskedCardNumber" instead of whole number

I have successfully integrated the paypal Swipe card SDK named"ios-here-sdk-dist-master". I am getting the card details like "maskedCardNumber, cardholderName, cardholderFirstName, cardholderLastName, expirationMonth, expirationYear, extraData, ksn, serial, asDictionary" except whole credit card number.
Note:- I am getting maskedCardNumber("4333XXXXXXXX3333") and I want whole number like "4333145785423333".
My Log
Main thread | PayPalHere: ROAM::onDecodeCompleted {
cardholderName = "xxxxxxxxxx ";
encTrack = 84298C945E6B142xxxxxxxxxxxxx6AA17F97;
expiryDate = xxxx;
formatID = 29;
ksn = 4029xxxxxC2508E0000D;
maskedPAN = 4333XXXXXXXX3333;
partialTrack = "xxxxxxxxxx ";
track1Status = 0;
track2Status = 0;
}
SDK:- Downloaded from Github
For more details click enter link description here.

How to display json data in UIWebview in iOS

I am trying to display json data in UIWebview.This is my json data
["{\"id\":\"6\",\"title\":null,\"description\":null,\"year\":\"2012\",\"date\":null}","{\"id\":\"4\",\"title\":\"Predictions proved correct in the year 2013\",\"description\":\"*<\\\/font> Financial system in America for this year is not indicated progress this year too. More problems will creep up.
\\r\\n*<\\\/font> Aggressive stage of Telangaana agitation- formation of seperate Telangaana state- bifurcation of state - sure indications are \\r\\n\\r\\npredicted.
\\r\\n*<\\\/font> Bad days for congress party was predicted long back. The same situations will continue.
\\r\\n*<\\\/font> The Gujarath CM - Sri Narendra Modi - Bright future is indicated. ( Care should be taken on health aspects).
\\r\\n*<\\\/font> Still danger is indicated for Indoneshia and Sumitra Islands\",\"year\":\"2013\",\"date\":null}"
{\"id\":\"3\",\"title\":\"2013-2014 Sri Vijayanama samvasthara Predictions\",\"description\":\"
జోతిస్యం అక్షర సత్యం
\\r\\nతెలంగాణా ఏర్పాటును గ్రహగతులు అనుసరించి మాత్రమే ఈ ఫలితము చెప్పడం జరిగింది . చరిత్రతమకమెన తెలంగాణా విషయంలో ములుగు సిద్ధాంతి వార్త పంచాంగంలో వ్రాసిన విధంగా అక్షరాల జరిగింది.
ప్రేత్యక తెలంగాణా విసయంలో అనేక రకాల మలుపులు తిరిగి ఎక్కడఎన ఆటంకం వస్తుందేమోనని బావించిన సందర్బాలు కూడా ఉన్నాయ్.
2011- 2012 శ్రీ ఖరనామ సవత్సరం వార్త పంచాంగంలో (58 వ పేజి , 18 లైనులో ) 2013-2014 శ్రీ విజయనామ సవత్సరం వార్త పంచాంగంలో తెలంగానా ఏర్పడుతుందని (40 వ పేజి 5 వ లైనులో )సిద్ధాంతి గారు వ్రాయడం జరిగింది
\\r\\n\\r\\nగమనిక : ఎంతోమంది జ్యోతిష్య, శాస్త్రవేత్తలు, సిద్దంతులు తలక్రిందులుగా తపస్సు చేసిన తెలంగాణా రాదనే చెప్పారు. ఒక్క ములుగు సిద్ధాంతి మాత్రమే మొదటి నుంచి చెబుతూనే వచ్చారు .\",\"year\":\"2014\",\"date\":null}"]
Now i need to display like this:
Financial system in America for this year is not indicated progress this year too. More problems will creep up.
*Aggressive stage of Telangaana agitation- formation of seperate Telangaana state- bifurcation of state - sure indications are predicted.
Bad days for congress party was predicted long back. The same situations will continue.
The Gujarath CM - Sri Narendra Modi - Bright future is indicated. ( Care should be taken on health aspects).
Still danger is indicated for Indoneshia and Sumitra Islands.
జోతిస్యం అక్షర సత్యం
తెలంగాణా ఏర్పాటును గ్రహగతులు అనుసరించి మాత్రమే ఈ ఫలితము చెప్పడం జరిగింది . చరిత్రతమకమెన తెలంగాణా విషయంలో ములుగు సిద్ధాంతి వార్త పంచాంగంలో వ్రాసిన విధంగా అక్షరాల జరిగింది.
ప్రేత్యక తెలంగాణా విసయంలో అనేక రకాల మలుపులు తిరిగి ఎక్కడఎన ఆటంకం వస్తుందేమోనని బావించిన సందర్బాలు కూడా ఉన్నాయ్.
2011- 2012 శ్రీ ఖరనామ సవత్సరం వార్త పంచాంగంలో (58 వ పేజి , 18 లైనులో ) 2013-2014 శ్రీ విజయనామ సవత్సరం వార్త పంచాంగంలో తెలంగానా ఏర్పడుతుందని (40 వ పేజి 5 వ లైనులో ) సిద్ధాంతి గారు వ్రాయడం జరిగింది
గమనిక : ఎంతోమంది జ్యోతిష్య, శాస్త్రవేత్తలు, సిద్దంతులు తలక్రిందులుగా తపస్సు చేసిన తెలంగాణా రాదనే చెప్పారు. ఒక్క సిద్ధాంతి మాత్రమే మొదటి నుంచి చెబుతూనే వచ్చారు
I am writing like this:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if(connection==urlConnection)
{
strResponse=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"%#",strResponse);
NSError *error;
jsonDict=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
NSLog(#"%#",jsonDict);
NSLog(#"object class == %#",[jsonDict class]);
stringArray=[jsonDict valueForKey:#"description"];
NSLog(#"%#",stringArray);
webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
[webView loadHTMLString:strResponse baseURL:nil];
[self.view addSubview:webView];
}
}
-(void)loadData
{
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults valueForKey:#"id"];
[defaults valueForKey:#"title"];
[defaults valueForKey:#"description"];
[defaults synchronize];
NSURL *url=[NSURL URLWithString:#"url"];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
urlConnection=[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
}
- (void)viewDidLoad{
[super viewDidLoad];
NSString *html = [NSString stringWithFormat:#"<html><p>here you json data</p></html>"];
[myWebView loadHTMLString:html baseURL:nil];
}
I hope it helps.

How to parse freeform street/postal address out of text, and into components

We do business largely in the United States and are trying to improve user experience by combining all the address fields into a single text area. But there are a few problems:
The address the user types may not be correct or in a standard format
The address must be separated into parts (street, city, state, etc.) to process credit card payments
Users may enter more than just their address (like their name or company with it)
Google can do this but the Terms of Service and query limits are prohibitive, especially on a tight budget
Apparently, this is a common question:
PHP script to parse address?
How do I parse the free format address to save into the DataBase
java postal address parser
More efficient way to extract address components
How can i show a pre populated postal address in contacts screen with street, city, zip on android
PHP regexp US address
Is there a way to isolate an address from the text around it and break it into pieces? Is there a regular expression to parse addresses?
I saw this question a lot when I worked for an address verification company. I'm posting the answer here to make it more accessible to programmers who are searching around with the same question. The company I was at processed billions of addresses, and we learned a lot in the process.
First, we need to understand a few things about addresses.
Addresses are not regular
This means that regular expressions are out. I've seen it all, from simple regular expressions that match addresses in a very specific format, to this:
/\s+(\d{2,5}\s+)(?![a|p]m\b)(([a-zA-Z|\s+]{1,5}){1,2})?([\s|,|.]+)?(([a-zA-Z|\s+]{1,30}){1,4})(court|ct|street|st|drive|dr|lane|ln|road|rd|blvd)([\s|,|.|;]+)?(([a-zA-Z|\s+]{1,30}){1,2})([\s|,|.]+)?\b(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|GU|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VI|VT|WA|WI|WV|WY)([\s|,|.]+)?(\s+\d{5})?([\s|,|.]+)/i
... to this where a 900+ line-class file generates a supermassive regular expression on the fly to match even more. I don't recommend these (for example, here's a fiddle of the above regex, that makes plenty of mistakes). There isn't an easy magic formula to get this to work. In theory and by theory, it's not possible to match addresses with a regular expression.
USPS Publication 28 documents the many formats of addresses that are possible, with all their keywords and variations. Worst of all, addresses are often ambiguous. Words can mean more than one thing ("St" can be "Saint" or "Street") and there are words that I'm pretty sure they invented. (Who knew that "Stravenue" was a street suffix?)
You'd need some code that really understands addresses, and if that code does exist, it's a trade secret. But you could probably roll your own if you're really into that.
Addresses come in unexpected shapes and sizes
Here are some contrived (but complete) addresses:
1) 102 main street
Anytown, state
2) 400n 600e #2, 52173
3) p.o. #104 60203
Even these are possibly valid:
4) 829 LKSDFJlkjsdflkjsdljf Bkpw 12345
5) 205 1105 14 90210
Obviously, these are not standardized. Punctuation and line breaks not guaranteed. Here's what's going on:
Number 1 is complete because it contains a street address and a city and state. With that information, there's enough to identify the address, and it can be considered "deliverable" (with some standardization).
Number 2 is complete because it also contains a street address (with secondary/unit number) and a 5-digit ZIP code, which is enough to identify an address.
Number 3 is a complete post office box format, as it contains a ZIP code.
Number 4 is also complete because the ZIP code is unique, meaning that a private entity or corporation has purchased that address space. A unique ZIP code is for high-volume or concentrated delivery spaces. Anything addressed to ZIP code 12345 goes to General Electric in Schenectady, NY. This example won't reach anyone in particular, but the USPS would still be able to deliver it.
Number 5 is also complete, believe it or not. With just those numbers, the full address can be discovered when parsed against a database of all possible addresses. Filling in the missing directionals, secondary designator, and ZIP+4 code is trivial when you see each number as a component. Here's what it looks like, fully expanded and standardized:
205 N 1105 W Apt 14
Beverly Hills CA 90210-5221
Address data is not your own
In most countries that provide official address data to licensed vendors, the address data itself belongs to the governing agency. In the US, the USPS owns the addresses. The same is true for Canada Post, Royal Mail, and others, though each country enforces or defines ownership a little differently. Knowing this is important, since it usually forbids reverse-engineering the address database. You have to be careful how to acquire, store, and use the data.
Google Maps is a common go-to for quick address fixes, but the TOS is rather prohibitive; for example, you can't use their data or APIs without showing a Google Map, and for non-commercial purposes only (unless you pay), and you can't store the data (except for temporary caching). Makes sense. Google's data is some of the best in the world. However, Google Maps does not verify the address. If an address does not exist, it will still show you where the address would be if it did exist (try it on your own street; use a house number that you know doesn't exist). This is useful sometimes, but be aware of that.
Nominatim's usage policy is similarly limiting, especially for high volume and commercial use, and the data is mostly drawn from free sources, so it isn't as well maintained (such is the nature of open projects) -- however, this may still suit your needs. It is supported by a great community.
The USPS itself has an API, but it goes down a lot and comes with no guarantees nor support. It might also be hard to use. Some people use it sparingly with no problems. But it's easy to miss that the USPS requires that you use their API only for confirming addresses to ship through them.
People expect addresses to be hard
Unfortunately, we've conditioned our society to expect addresses to be complicated. There's dozens of good UX articles all over the Internet about this, but the fact is, if you have an address form with individual fields, that's what users expect, even though it makes it harder for edge-case addresses that don't fit the format the form is expecting, or maybe the form requires a field it shouldn't. Or users don't know where to put a certain part of their address.
I could go on and on about the bad UX of checkout forms these days, but instead I'll just say that combining the addresses into a single field will be a welcome change -- people will be able to type their address how they see fit, rather than trying to figure out your lengthy form. However, this change will be unexpected and users may find it a little jarring at first. Just be aware of that.
Part of this pain can be alleviated by putting the country field out front, before the address. When they fill out the country field first, you know how to make your form appear. Maybe you have a good way to deal with single-field US addresses, so if they select United States, you can reduce your form to a single field, otherwise show the component fields. Just things to think about!
Now we know why it's hard; what can you do about it?
The USPS licenses vendors through a process called CASS™ Certification to provide verified addresses to customers. These vendors have access to the USPS database, updated monthly. Their software must conform to rigorous standards to be certified, and they don't often require agreement to such limiting terms as discussed above.
There are many CASS-Certified companies that can process lists or have APIs: Melissa Data, Experian QAS, and SmartyStreets to name a few.
(Due to getting flak for "advertising" I've truncated my answer at this point. It's up to you to find a solution that works for you.)
The Truth: Really, folks, I don't work at any of these companies. It's not an advertisement.
There are many street address parsers. They come in two basic flavors - ones that have databases of place names and street names, and ones that don't.
A regular expression street address parser can get up to about a 95% success rate without much trouble. Then you start hitting the unusual cases. The Perl one in CPAN, "Geo::StreetAddress::US", is about that good. There are Python and Javascript ports of that, all open source. I have an improved version in Python which moves the success rate up slightly by handling more cases. To get the last 3% right, though, you need databases to help with disambiguation.
A database with 3-digit ZIP codes and US state names and abbreviations is a big help. When a parser sees a consistent postal code and state name, it can start to lock on to the format. This works very well for the US and UK.
Proper street address parsing starts from the end and works backwards. That's how the USPS systems do it. Addresses are least ambiguous at the end, where country names, city names, and postal codes are relatively easy to recognize. Street names can usually be isolated. Locations on streets are the most complex to parse; there you encounter things such as "Fifth Floor" and "Staples Pavillion". That's when a database is a big help.
UPDATE: Geocode.xyz now works worldwide. For examples see https://geocode.xyz
For USA, Mexico and Canada, see geocoder.ca.
For example:
Input: something going on near the intersection of main and arthur kill rd new york
Output:
<geodata>
<latt>40.5123510000</latt>
<longt>-74.2500500000</longt>
<AreaCode>347,718</AreaCode>
<TimeZone>America/New_York</TimeZone>
<standard>
<street1>main</street1>
<street2>arthur kill</street2>
<stnumber/>
<staddress/>
<city>STATEN ISLAND</city>
<prov>NY</prov>
<postal>11385</postal>
<confidence>0.9</confidence>
</standard>
</geodata>
You may also check the results in the web interface or get output as Json or Jsonp. eg. I'm looking for restaurants around 123 Main Street, New York
No code? For shame!
Here is a simple JavaScript address parser. It's pretty awful for every single reason that Matt gives in his dissertation above (which I almost 100% agree with: addresses are complex types, and humans make mistakes; better to outsource and automate this - when you can afford to).
But rather than cry, I decided to try:
This code works OK for parsing most Esri results for findAddressCandidate and also with some other (reverse)geocoders that return single-line address where street/city/state are delimited by commas. You can extend if you want or write country-specific parsers. Or just use this as case study of how challenging this exercise can be or at how lousy I am at JavaScript. I admit I only spent about thirty mins on this (future iterations could add caches, zip validation, and state lookups as well as user location context), but it worked for my use case: End user sees form that parses geocode search response into 4 textboxes. If address parsing comes out wrong (which is rare unless source data was poor) it's no big deal - the user gets to verify and fix it! (But for automated solutions could either discard/ignore or flag as error so dev can either support the new format or fix source data.)
/*
address assumptions:
- US addresses only (probably want separate parser for different countries)
- No country code expected.
- if last token is a number it is probably a postal code
-- 5 digit number means more likely
- if last token is a hyphenated string it might be a postal code
-- if both sides are numeric, and in form #####-#### it is more likely
- if city is supplied, state will also be supplied (city names not unique)
- zip/postal code may be omitted even if has city & state
- state may be two-char code or may be full state name.
- commas:
-- last comma is usually city/state separator
-- second-to-last comma is possibly street/city separator
-- other commas are building-specific stuff that I don't care about right now.
- token count:
-- because units, street names, and city names may contain spaces token count highly variable.
-- simplest address has at least two tokens: 714 OAK
-- common simple address has at least four tokens: 714 S OAK ST
-- common full (mailing) address has at least 5-7:
--- 714 OAK, RUMTOWN, VA 59201
--- 714 S OAK ST, RUMTOWN, VA 59201
-- complex address may have a dozen or more:
--- MAGICICIAN SUPPLY, LLC, UNIT 213A, MAGIC TOWN MALL, 13 MAGIC CIRCLE DRIVE, LAND OF MAGIC, MA 73122-3412
*/
var rawtext = $("textarea").val();
var rawlist = rawtext.split("\n");
function ParseAddressEsri(singleLineaddressString) {
var address = {
street: "",
city: "",
state: "",
postalCode: ""
};
// tokenize by space (retain commas in tokens)
var tokens = singleLineaddressString.split(/[\s]+/);
var tokenCount = tokens.length;
var lastToken = tokens.pop();
if (
// if numeric assume postal code (ignore length, for now)
!isNaN(lastToken) ||
// if hyphenated assume long zip code, ignore whether numeric, for now
lastToken.split("-").length - 1 === 1) {
address.postalCode = lastToken;
lastToken = tokens.pop();
}
if (lastToken && isNaN(lastToken)) {
if (address.postalCode.length && lastToken.length === 2) {
// assume state/province code ONLY if had postal code
// otherwise it could be a simple address like "714 S OAK ST"
// where "ST" for "street" looks like two-letter state code
// possibly this could be resolved with registry of known state codes, but meh. (and may collide anyway)
address.state = lastToken;
lastToken = tokens.pop();
}
if (address.state.length === 0) {
// check for special case: might have State name instead of State Code.
var stateNameParts = [lastToken.endsWith(",") ? lastToken.substring(0, lastToken.length - 1) : lastToken];
// check remaining tokens from right-to-left for the first comma
while (2 + 2 != 5) {
lastToken = tokens.pop();
if (!lastToken) break;
else if (lastToken.endsWith(",")) {
// found separator, ignore stuff on left side
tokens.push(lastToken); // put it back
break;
} else {
stateNameParts.unshift(lastToken);
}
}
address.state = stateNameParts.join(' ');
lastToken = tokens.pop();
}
}
if (lastToken) {
// here is where it gets trickier:
if (address.state.length) {
// if there is a state, then assume there is also a city and street.
// PROBLEM: city may be multiple words (spaces)
// but we can pretty safely assume next-from-last token is at least PART of the city name
// most cities are single-name. It would be very helpful if we knew more context, like
// the name of the city user is in. But ignore that for now.
// ideally would have zip code service or lookup to give city name for the zip code.
var cityNameParts = [lastToken.endsWith(",") ? lastToken.substring(0, lastToken.length - 1) : lastToken];
// assumption / RULE: street and city must have comma delimiter
// addresses that do not follow this rule will be wrong only if city has space
// but don't care because Esri formats put comma before City
var streetNameParts = [];
// check remaining tokens from right-to-left for the first comma
while (2 + 2 != 5) {
lastToken = tokens.pop();
if (!lastToken) break;
else if (lastToken.endsWith(",")) {
// found end of street address (may include building, etc. - don't care right now)
// add token back to end, but remove trailing comma (it did its job)
tokens.push(lastToken.endsWith(",") ? lastToken.substring(0, lastToken.length - 1) : lastToken);
streetNameParts = tokens;
break;
} else {
cityNameParts.unshift(lastToken);
}
}
address.city = cityNameParts.join(' ');
address.street = streetNameParts.join(' ');
} else {
// if there is NO state, then assume there is NO city also, just street! (easy)
// reasoning: city names are not very original (Portland, OR and Portland, ME) so if user wants city they need to store state also (but if you are only ever in Portlan, OR, you don't care about city/state)
// put last token back in list, then rejoin on space
tokens.push(lastToken);
address.street = tokens.join(' ');
}
}
// when parsing right-to-left hard to know if street only vs street + city/state
// hack fix for now is to shift stuff around.
// assumption/requirement: will always have at least street part; you will never just get "city, state"
// could possibly tweak this with options or more intelligent parsing&sniffing
if (!address.city && address.state) {
address.city = address.state;
address.state = '';
}
if (!address.street) {
address.street = address.city;
address.city = '';
}
return address;
}
// get list of objects with discrete address properties
var addresses = rawlist
.filter(function(o) {
return o.length > 0
})
.map(ParseAddressEsri);
$("#output").text(JSON.stringify(addresses));
console.log(addresses);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea>
27488 Stanford Ave, Bowden, North Dakota
380 New York St, Redlands, CA 92373
13212 E SPRAGUE AVE, FAIR VALLEY, MD 99201
1005 N Gravenstein Highway, Sebastopol CA 95472
A. P. Croll & Son 2299 Lewes-Georgetown Hwy, Georgetown, DE 19947
11522 Shawnee Road, Greenwood, DE 19950
144 Kings Highway, S.W. Dover, DE 19901
Intergrated Const. Services 2 Penns Way Suite 405, New Castle, DE 19720
Humes Realty 33 Bridle Ridge Court, Lewes, DE 19958
Nichols Excavation 2742 Pulaski Hwy, Newark, DE 19711
2284 Bryn Zion Road, Smyrna, DE 19904
VEI Dover Crossroads, LLC 1500 Serpentine Road, Suite 100 Baltimore MD 21
580 North Dupont Highway, Dover, DE 19901
P.O. Box 778, Dover, DE 19903
714 S OAK ST
714 S OAK ST, RUM TOWN, VA, 99201
3142 E SPRAGUE AVE, WHISKEY VALLEY, WA 99281
27488 Stanford Ave, Bowden, North Dakota
380 New York St, Redlands, CA 92373
</textarea>
<div id="output">
</div>
For U.S. address parsing, I prefer using the usaddress package that is available in pip.
python3 -m pip install usaddress
Usage sample:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# address_parser.py
import sys
from usaddress import tag
from json import dumps, loads
if __name__ == '__main__':
tag_mapping = {
'Recipient': 'recipient',
'AddressNumber': 'addressStreet',
'AddressNumberPrefix': 'addressStreet',
'AddressNumberSuffix': 'addressStreet',
'StreetName': 'addressStreet',
'StreetNamePreDirectional': 'addressStreet',
'StreetNamePreModifier': 'addressStreet',
'StreetNamePreType': 'addressStreet',
'StreetNamePostDirectional': 'addressStreet',
'StreetNamePostModifier': 'addressStreet',
'StreetNamePostType': 'addressStreet',
'CornerOf': 'addressStreet',
'IntersectionSeparator': 'addressStreet',
'LandmarkName': 'addressStreet',
'USPSBoxGroupID': 'addressStreet',
'USPSBoxGroupType': 'addressStreet',
'USPSBoxID': 'addressStreet',
'USPSBoxType': 'addressStreet',
'BuildingName': 'addressStreet',
'OccupancyType': 'addressStreet',
'OccupancyIdentifier': 'addressStreet',
'SubaddressIdentifier': 'addressStreet',
'SubaddressType': 'addressStreet',
'PlaceName': 'addressCity',
'StateName': 'addressState',
'ZipCode': 'addressPostalCode',
}
try:
address, _ = tag(' '.join(sys.argv[1:]), tag_mapping=tag_mapping)
except:
with open('failed_address.txt', 'a') as fp:
fp.write(sys.argv[1] + '\n')
print(dumps({}))
else:
print(dumps(dict(address)))
Running address_parser.py:
python3 address_parser.py 9757 East Arcadia Ave. Saugus MA 01906
{"addressStreet": "9757 East Arcadia Ave.", "addressCity": "Saugus", "addressState": "MA", "addressPostalCode": "01906"}
I'm late to the party, but here is an Excel VBA script I wrote years ago for Australia. It can be easily modified to support other Countries. I've made a GitHub repository of the C# code here. I've hosted it on my site and you can download it here: http://jeremythompson.net/Rocks/ParseAddress.xlsm
Strategy
For any country with a PostCode that's numeric or can be matched with a RegEx my strategy works very well:
First we detect the First and Surname which are assumed to be the top line. Its easy to skip the name and start with the address by unticking the checkbox (called 'Name is top row' as shown below).
Next its safe to expect the Address consisting of the Street and Number come before the Suburb and the St, Pde, Ave, Av, Rd, Cres, loop, etc is a separator.
Detecting the Suburb vs the State and even Country can trick the most sophisticated parsers as there can be conflicts. To overcome this I use a PostCode look up based on the fact that after stripping Street and Apartment/Unit numbers as well as the PoBox,Ph,Fax,Mobile etc, only the PostCode number will remain. This is easy to match with a regEx to then look up the suburb(s) and country.
Your National Post Office Service will provide a list of post codes with Suburbs and States free of charge that you can store in an excel sheet, db table, text/json/xml file, etc.
Finally, since some Post Codes have multiple Suburbs we check which suburb appears in the Address.
Example
VBA Code
DISCLAIMER, I know this code is not perfect, or even written well however its very easy to convert to any programming language and run in any type of application. The strategy is the answer depending on your country and rules, take this code as an example:
Option Explicit
Private Const TopRow As Integer = 0
Public Sub ParseAddress()
Dim strArr() As String
Dim sigRow() As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim Stat As String
Dim SpaceInName As Integer
Dim Temp As String
Dim PhExt As String
On Error Resume Next
Temp = ActiveSheet.Range("Address")
'Split info into array
strArr = Split(Temp, vbLf)
'Trim the array
For i = 0 To UBound(strArr)
strArr(i) = VBA.Trim(strArr(i))
Next i
'Remove empty items/rows
ReDim sigRow(LBound(strArr) To UBound(strArr))
For i = LBound(strArr) To UBound(strArr)
If Trim(strArr(i)) <> "" Then
sigRow(j) = strArr(i)
j = j + 1
End If
Next i
ReDim Preserve sigRow(LBound(strArr) To j)
'Find the name (MUST BE ON THE FIRST ROW UNLESS CHECKBOX UNTICKED)
i = TopRow
If ActiveSheet.Shapes("chkFirst").ControlFormat.Value = 1 Then
SpaceInName = InStr(1, sigRow(i), " ", vbTextCompare) - 1
If ActiveSheet.Shapes("chkConfirm").ControlFormat.Value = 0 Then
ActiveSheet.Range("FirstName") = VBA.Left(sigRow(i), SpaceInName)
Else
If MsgBox("First Name: " & VBA.Mid$(sigRow(i), 1, SpaceInName), vbQuestion + vbYesNo, "Confirm Details") = vbYes Then ActiveSheet.Range("FirstName") = VBA.Left(sigRow(i), SpaceInName)
End If
If ActiveSheet.Shapes("chkConfirm").ControlFormat.Value = 0 Then
ActiveSheet.Range("Surname") = VBA.Mid(sigRow(i), SpaceInName + 2)
Else
If MsgBox("Surame: " & VBA.Mid(sigRow(i), SpaceInName + 2), vbQuestion + vbYesNo, "Confirm Details") = vbYes Then ActiveSheet.Range("Surname") = VBA.Mid(sigRow(i), SpaceInName + 2)
End If
sigRow(i) = ""
End If
'Find the Street by looking for a "St, Pde, Ave, Av, Rd, Cres, loop, etc"
For i = 1 To UBound(sigRow)
If Len(sigRow(i)) > 0 Then
For j = 0 To 8
If InStr(1, VBA.UCase(sigRow(i)), Street(j), vbTextCompare) > 0 Then
'Find the position of the street in order to get the suburb
SpaceInName = InStr(1, VBA.UCase(sigRow(i)), Street(j), vbTextCompare) + Len(Street(j)) - 1
'If its a po box then add 5 chars
If VBA.Right(Street(j), 3) = "BOX" Then SpaceInName = SpaceInName + 5
If ActiveSheet.Shapes("chkConfirm").ControlFormat.Value = 0 Then
ActiveSheet.Range("Street") = VBA.Mid(sigRow(i), 1, SpaceInName)
Else
If MsgBox("Street Address: " & VBA.Mid(sigRow(i), 1, SpaceInName), vbQuestion + vbYesNo, "Confirm Details") = vbYes Then ActiveSheet.Range("Street") = VBA.Mid(sigRow(i), 1, SpaceInName)
End If
'Trim the Street, Number leaving the Suburb if its exists on the same line
sigRow(i) = VBA.Mid(sigRow(i), SpaceInName) + 2
sigRow(i) = Replace(sigRow(i), VBA.Mid(sigRow(i), 1, SpaceInName), "")
GoTo PastAddress:
End If
Next j
End If
Next i
PastAddress:
'Mobile
For i = 1 To UBound(sigRow)
If Len(sigRow(i)) > 0 Then
For j = 0 To 3
Temp = Mb(j)
If VBA.Left(VBA.UCase(sigRow(i)), Len(Temp)) = Temp Then
If ActiveSheet.Shapes("chkConfirm").ControlFormat.Value = 0 Then
ActiveSheet.Range("Mobile") = VBA.Mid(sigRow(i), Len(Temp) + 2)
Else
If MsgBox("Mobile: " & VBA.Mid(sigRow(i), Len(Temp) + 2), vbQuestion + vbYesNo, "Confirm Details") = vbYes Then ActiveSheet.Range("Mobile") = VBA.Mid(sigRow(i), Len(Temp) + 2)
End If
sigRow(i) = ""
GoTo PastMobile:
End If
Next j
End If
Next i
PastMobile:
'Phone
For i = 1 To UBound(sigRow)
If Len(sigRow(i)) > 0 Then
For j = 0 To 1
Temp = Ph(j)
If VBA.Left(VBA.UCase(sigRow(i)), Len(Temp)) = Temp Then
'TODO: Detect the intl or national extension here.. or if we can from the postcode.
If ActiveSheet.Shapes("chkConfirm").ControlFormat.Value = 0 Then
ActiveSheet.Range("Phone") = VBA.Mid(sigRow(i), Len(Temp) + 3)
Else
If MsgBox("Phone: " & VBA.Mid(sigRow(i), Len(Temp) + 3), vbQuestion + vbYesNo, "Confirm Details") = vbYes Then ActiveSheet.Range("Phone") = VBA.Mid(sigRow(i), Len(Temp) + 3)
End If
sigRow(i) = ""
GoTo PastPhone:
End If
Next j
End If
Next i
PastPhone:
'Email
For i = 1 To UBound(sigRow)
If Len(sigRow(i)) > 0 Then
'replace with regEx search
If InStr(1, sigRow(i), "#", vbTextCompare) And InStr(1, VBA.UCase(sigRow(i)), ".CO", vbTextCompare) Then
Dim email As String
email = sigRow(i)
email = Replace(VBA.UCase(email), "EMAIL:", "")
email = Replace(VBA.UCase(email), "E-MAIL:", "")
email = Replace(VBA.UCase(email), "E:", "")
email = Replace(VBA.UCase(Trim(email)), "E ", "")
email = VBA.LCase(email)
If ActiveSheet.Shapes("chkConfirm").ControlFormat.Value = 0 Then
ActiveSheet.Range("Email") = email
Else
If MsgBox("Email: " & email, vbQuestion + vbYesNo, "Confirm Details") = vbYes Then ActiveSheet.Range("Email") = email
End If
sigRow(i) = ""
Exit For
End If
End If
Next i
'Now the only remaining items will be the postcode, suburb, country
'there shouldn't be any numbers (eg. from PoBox,Ph,Fax,Mobile) except for the Post Code
'Join the string and filter out the Post Code
Temp = Join(sigRow, vbCrLf)
Temp = Trim(Temp)
For i = 1 To Len(Temp)
Dim postCode As String
postCode = VBA.Mid(Temp, i, 4)
'In Australia PostCodes are 4 digits
If VBA.Mid(Temp, i, 1) <> " " And IsNumeric(postCode) Then
If ActiveSheet.Shapes("chkConfirm").ControlFormat.Value = 0 Then
ActiveSheet.Range("PostCode") = postCode
Else
If MsgBox("Post Code: " & postCode, vbQuestion + vbYesNo, "Confirm Details") = vbYes Then ActiveSheet.Range("PostCode") = postCode
End If
'Lookup the Suburb and State based on the PostCode, the PostCode sheet has the lookup
Dim mySuburbArray As Range
Set mySuburbArray = Sheets("PostCodes").Range("A2:B16670")
Dim suburbs As String
For j = 1 To mySuburbArray.Columns(1).Cells.Count
If mySuburbArray.Cells(j, 1) = postCode Then
'Check if the suburb is listed in the address
If InStr(1, UCase(Temp), mySuburbArray.Cells(j, 2), vbTextCompare) > 0 Then
'Set the Suburb and State
ActiveSheet.Range("Suburb") = mySuburbArray.Cells(j, 2)
Stat = mySuburbArray.Cells(j, 3)
ActiveSheet.Range("State") = Stat
'Knowing the State - for Australia we can get the telephone Ext
PhExt = PhExtension(VBA.UCase(Stat))
ActiveSheet.Range("PhExt") = PhExt
'remove the phone extension from the number
Dim prePhone As String
prePhone = ActiveSheet.Range("Phone")
prePhone = Replace(prePhone, PhExt & " ", "")
prePhone = Replace(prePhone, "(" & PhExt & ") ", "")
prePhone = Replace(prePhone, "(" & PhExt & ")", "")
ActiveSheet.Range("Phone") = prePhone
Exit For
End If
End If
Next j
Exit For
End If
Next i
End Sub
Private Function PhExtension(ByVal State As String) As String
Select Case State
Case Is = "NSW"
PhExtension = "02"
Case Is = "QLD"
PhExtension = "07"
Case Is = "VIC"
PhExtension = "03"
Case Is = "NT"
PhExtension = "04"
Case Is = "WA"
PhExtension = "05"
Case Is = "SA"
PhExtension = "07"
Case Is = "TAS"
PhExtension = "06"
End Select
End Function
Private Function Ph(ByVal Num As Integer) As String
Select Case Num
Case Is = 0
Ph = "PH"
Case Is = 1
Ph = "PHONE"
'Case Is = 2
'Ph = "P"
End Select
End Function
Private Function Mb(ByVal Num As Integer) As String
Select Case Num
Case Is = 0
Mb = "MB"
Case Is = 1
Mb = "MOB"
Case Is = 2
Mb = "CELL"
Case Is = 3
Mb = "MOBILE"
'Case Is = 4
'Mb = "M"
End Select
End Function
Private Function Fax(ByVal Num As Integer) As String
Select Case Num
Case Is = 0
Fax = "FAX"
Case Is = 1
Fax = "FACSIMILE"
'Case Is = 2
'Fax = "F"
End Select
End Function
Private Function State(ByVal Num As Integer) As String
Select Case Num
Case Is = 0
State = "NSW"
Case Is = 1
State = "QLD"
Case Is = 2
State = "VIC"
Case Is = 3
State = "NT"
Case Is = 4
State = "WA"
Case Is = 5
State = "SA"
Case Is = 6
State = "TAS"
End Select
End Function
Private Function Street(ByVal Num As Integer) As String
Select Case Num
Case Is = 0
Street = " ST"
Case Is = 1
Street = " RD"
Case Is = 2
Street = " AVE"
Case Is = 3
Street = " AV"
Case Is = 4
Street = " CRES"
Case Is = 5
Street = " LOOP"
Case Is = 6
Street = "PO BOX"
Case Is = 7
Street = " STREET"
Case Is = 8
Street = " ROAD"
Case Is = 9
Street = " AVENUE"
Case Is = 10
Street = " CRESENT"
Case Is = 11
Street = " PARADE"
Case Is = 12
Street = " PDE"
Case Is = 13
Street = " LANE"
Case Is = 14
Street = " COURT"
Case Is = 15
Street = " BLVD"
Case Is = 16
Street = "P.O. BOX"
Case Is = 17
Street = "P.O BOX"
Case Is = 18
Street = "PO BOX"
Case Is = 19
Street = "POBOX"
End Select
End Function

Grails controller error

def results = {
def results = [:]
def conferences = Conference.list() // lista das conferencias
String [] conf_origin // array de strings da indexação da classe
String [] conf_search = params.conferenceName.split() // array de strings palavras da pesquisa
boolean test // teste double for
conferences.each{
conf_origin = "hi i'm john".split() // indexação
//conf_origin = "aveiroa".split()
OUTER: for(int i = 0; i< conf_origin.length; i++){
for(int j = 0; j< conf_search.length; j++) {
if(conf_origin[i] == conf_search[j]){
test = true
results.put(it.id, it)
break OUTER;
}
}
}
}
return [results : results]
}
Hey i am having this problem. If i return: "[conferences: conferences]" my gsp sucessfully do what i want. Altought, when i return '[results: results]' which is suposelly a filtered map of conferences, the folowing error is displayed and i cant figure it out why:
Exception Message: No such property: yearCount for class: java.util.LinkedHashMap$Entry
PS. Basically, i have
String [] conf_origin ---> which is a String array of words
String [] conf_search ---> which is a string array of introduced words in search bar.
Then i compare both arrays, and if there's one match, i break the for and add that conference object to results.
conferences is a List (of Conference, but it's untyped in Groovy), and results is a Map. You need either to:
make it a List of Conference
or return [conferences: results.values()]
or adjust your GSP page to iterate over a Map.
Note that conferences is a variable name your GSP code relies onto.

Resources