+ Reply
Page 7 of 8 FirstFirst ... 5678 LastLast
Results 121 to 140 of 141

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Improving our Coding Skills

is a discussion within the

File Mods

forums, a part of the

iPhone Modding

section;
So it's as simple, in my case, by way of example, to use a find all & replace all command in NotePad to change obj.one to obj.address[1] ?? It's that
...
  1. #121
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    So it's as simple, in my case, by way of example, to use a find all & replace all command in NotePad to change
    obj.one to obj.address[1] ?? It's that simple?

    And that will work even if the object is part of a larger expression like
    obj.one.split(",")........
    Running the above Replace All will change that nested object to:
    obj.address[1].split(",")........ ?
    Here to help if I can. If I can't I know someone who can!

  2. #122
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,291
    Thanks
    41,239
    Thanked 17,404 Times in 6,356 Posts

    Yes
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  3. The Following 3 Users Say Thank You to King_O_Hill For This Useful Post:

    Dacal (05-01-2014), NewdestinyX (05-01-2014), RKO1195 (05-03-2014)

  4. #123
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Now THAT was easy…
    Here to help if I can. If I can't I know someone who can!

  5. #124
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    The new code is working very nicely in my GoogleLocation iWidget, Dacal!! Thank you again for continuing to improve my skills. I learned a lot from this recent series of questions. I am now learning what the "for" command is all about and what i++ plus does.

    One other question.. Does a refresh timer run when you're testing on a computer? So if you're using a URL call - even though you don't refresh the widget manually within your editor, is the refresh timer in your code sending out new calls to the URL at the refresh interval?

    If so - that would sure explain why some days Google has blocked my IP address for having exceeded daily calls to their server..
    Here to help if I can. If I can't I know someone who can!

  6. #125
    Addicted to Code Dacal's Avatar
    Join Date
    Nov 2010
    Posts
    1,891
    Thanks
    2,903
    Thanked 8,487 Times in 1,500 Posts

    Hi Newdestiny,

    Thx !

    If you have set up a timeout or interval for updating the coordinates, yes. It will work on your computer and/or HTML viever (same as on your phone).


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  7. The Following User Says Thank You to Dacal For This Useful Post:

    RKO1195 (08-16-2014)

  8. #126
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Quote Originally Posted by Dacal View Post
    Hi Newdestiny,

    Thx !

    If you have set up a timeout or interval for updating the coordinates, yes. It will work on your computer and/or HTML viever (same as on your phone).
    Oh MY!! Well that explains a lot.. LOL!! In addition to TacoHTMLEdit's Live Preview function sending a new URL call to Google Maps API each time I type a 'character' (it auto refreshes and resends the call) - I've never commented out the refreshTimer for function updateLocation().. LOL!! So no wonder I've occasionally maxxed out my calls to Google's free api and they 'blocked my IP' for rest of day. They must have considered me a 'spammer'.. or 'business user'..

    Okay.. I will comment out the refreshTimer when I'm doing testing work on my computer..

    Thx!
    Here to help if I can. If I can't I know someone who can!

  9. #127
    Addicted to Code Dacal's Avatar
    Join Date
    Nov 2010
    Posts
    1,891
    Thanks
    2,903
    Thanked 8,487 Times in 1,500 Posts

    Quote Originally Posted by NewdestinyX View Post
    Oh MY!! Well that explains a lot.. LOL!! In addition to TacoHTMLEdit's Live Preview function sending a new URL call to Google Maps API each time I type a 'character' (it auto refreshes and resends the call) - I've never commented out the refreshTimer for function updateLocation().. LOL!! So no wonder I've occasionally maxxed out my calls to Google's free api and they 'blocked my IP' for rest of day. They must have considered me a 'spammer'.. or 'business user'..

    Okay.. I will comment out the refreshTimer when I'm doing testing work on my computer..

    Thx!
    Best way for testing, save the data in XML format and change the URL in the javascript to load this local file.

    ++


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  10. The Following 2 Users Say Thank You to Dacal For This Useful Post:

    King_O_Hill (05-02-2014), RKO1195 (05-03-2014)

  11. #128
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Quote Originally Posted by Dacal View Post
    Best way for testing, save the data in XML format and change the URL in the javascript to load this local file.

    ++
    Except my particular widget tries to decipher, from Google's 8 fields of formatted address data, the types of political regions of an area including counties and townships, parishes, census areas, CDP's and neighborhoods.. So I must test many different coordinates (from myLocation.txt and "discover" how to auto infer these sections from many different places around the world.

    Your xml method is fine when all you need to do is test CSS positioning and I already wrote a "function noJsonCall() " with fake variables to test positioning and formatting. But most of my testing is with lat long coordinates from hundreds of places around the world. Need a fresh JQuery from URL each time.

    Google allows 2000 calls a day for free.. So with my refreshTimer off now I should be good.

    Thanks Dacal!!
    Here to help if I can. If I can't I know someone who can!

  12. The Following User Says Thank You to NewdestinyX For This Useful Post:

    Dacal (05-03-2014)

  13. #129
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Okay - Dacal, King, Jake.. riddle me this....

    This particular code line changes "VILLANONA" to "Villanova".
    Code:
    obj.add[1] = obj.add[1].toLowerCase().replace(/\b[a-z]/g, function(letter) {return letter.toUpperCase();});
    But for some reason - I noticed this last week while I was in Spain - that that same code line has problems with foreign characters. And renders this "CharmartíN" from this "CHARMARTÍN". In other examples - all letters after the foreign character stay capital. How could I modify the above code line to make sure the characters after a foreign character stay small case after an initial cap of the word?

    Thanks in advance,
    Grant
    Here to help if I can. If I can't I know someone who can!

  14. #130
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    When coding really starts to get fun is when you start to CREATE code out of other syntax you've learned and find that it actually works!! I've never seen this particular line of code before - but figure it might work and it does. For a while I've been using the "in" code to compare an object's contents against an array of other other text strings.. But I remember Jake (Groovy Carrot) telling me that that the 'in' syntax, requiring each string to be set to a value of "" was needless resource taking... So I wondered if this would work and be less resource intensive..
    Code:
    var townships = ["AR", "IL", "IN", "IA", "KS", "MI", "MN", "MO", "NC", "ND", "NE", "NH", "NJ", "OH", "PA", "SD"]; //states that have townships
    if (townships.indexOf(obj.statecode) > -1) {var TownshipState = true; var TownshipTxt = " Township";} else {var TownshipState = false; var TownshipTxt = "";}
    I had seen [obj.icon] - which is parsed as a number coming from yahoo - be used as something in UniAW you could 'divide by'. So by naming the object itself, which contains a number, you could use that in place of an ACTUAL number. That made me wonder if indexOF's string between the parentheses ( ) could also be an 'object' name...! And it CAN!!.. I also learned that any one variable can be a series (an array) of string texts separated by commas.. I learned this by learning how to do weather description in UniAW with it's long WeatherDesc variable. So synthesizing those two other syntaxes I observed enabled me to create a more resource-efficient (I think) syntax for comparing an object's string of text against an array of texts -- in my case -- seeing if the contents of obj.statecode (parsed from WW's XML file) matches one of the statecodes in my array of states that have townships.

    It worked! LOVE it!!! So I'm thinking that my above code is less resource intensive than what I used before.

    Code:
    if (obj.statecode in {'AR':"",'IL':"",'IN':"",'IA':"",'KS':"",'MI':"",'MN':"",'MO':"",'NC':"",'ND':"",'NE':"",'NH':"",'NJ':"",'OH':"",'PA':"",'SD':""})
    {var TownshipState = true; var TownshipTxt = " Township";} else {var TownshipState = false; var TownshipTxt = "";}
    Yes?
    Here to help if I can. If I can't I know someone who can!

  15. #131
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,291
    Thanks
    41,239
    Thanked 17,404 Times in 6,356 Posts

    Simply put, yes.
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  16. The Following User Says Thank You to King_O_Hill For This Useful Post:

    NewdestinyX (06-09-2014)

  17. #132
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Thanks, Brian. Am I also then correctly applying the concept I've learned - such that this series of indexOf + || (or) statements:

    Code:
    if ((obj.add[1].indexOf("&") > -1) || (obj.add[1].indexOf("@") > -1) || (obj.add[1].indexOf("At") > -1) || (obj.add[1].indexOf("Circle") > -1) || (obj.add[1].indexOf("Street") > -1) || (obj.add[1].indexOf("Field") > -1))
    {puncone = true;} else {puncone = false;}
    if ((obj.add[2].indexOf("&") > -1) || (obj.add[2].indexOf("@") > -1) || (obj.add[2].indexOf("At") > -1) || (obj.add[2].indexOf("Circle") > -1) || (obj.add[2].indexOf("Street") > -1))
    {punctwo = true;} else {punctwo = false;}
    if ((obj.add[3].indexOf("&") > -1) || (obj.add[3].indexOf("@") > -1) || (obj.add[3].indexOf("At") > -1) || (obj.add[3].indexOf("Circle") > -1) || (obj.add[3].indexOf("Street") > -1))
    {puncthree = true;} else {puncthree = false;}
    ...can be reduced to this:
    Code:
    var streetsymbol = ["&", "@", "At", "Circle", "Street", "Center", "Field"];
    if (streetsymbol.indexOf(obj.add[1]) > -1) {puncone = true;} else {puncone = false;}
    if (streetsymbol.indexOf(obj.add[2]) > -1) {punctwo = true;} else {punctwo = false;}
    if (streetsymbol.indexOf(obj.add[3]) > -1) {puncthree = true;} else {puncthree = false;}
    Right?
    Here to help if I can. If I can't I know someone who can!

  18. #133
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,291
    Thanks
    41,239
    Thanked 17,404 Times in 6,356 Posts

    Looks right bro.
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  19. #134
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Quote Originally Posted by King_O_Hill View Post
    Looks right bro.
    Nah.. Bummer.. The condition is returning false not true.. For some reason - it's not working.. I'll get to the bottom of it.. thanks for taking a look.. I'm getting obsessed now with making my code more efficient.. Less lines if at all possible.. I was always amazed when I got back something from Dacal - how much he'd removed.. I'm determining not to have someone do my work anymore... and I'm enjoying the discovery.
    Here to help if I can. If I can't I know someone who can!

  20. #135
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Okay.. Figured it out... For this particular operation -- where you have an object within which you want to identify any one of several strings of text -- You can either list separate indexOf's separated by || (or) as in my original or the only way to reduce it is with using the .match syntax.

    So this:
    Code:
    if ((obj.add[1].indexOf("&") > -1) || (obj.add[1].indexOf("@") > -1) || (obj.add[1].indexOf("At") > -1) || (obj.add[1].indexOf("Circle") > -1) || (obj.add[1].indexOf("Street") > -1) || (obj.add[1].indexOf("Field") > -1))
    {puncone = true;} else {puncone = false;}
    if ((obj.add[2].indexOf("&") > -1) || (obj.add[2].indexOf("@") > -1) || (obj.add[2].indexOf("At") > -1) || (obj.add[2].indexOf("Circle") > -1) || (obj.add[2].indexOf("Street") > -1) || (obj.add[1].indexOf("Field") > -1))
    {punctwo = true;} else {punctwo = false;}
    if ((obj.add[3].indexOf("&") > -1) || (obj.add[3].indexOf("@") > -1) || (obj.add[3].indexOf("At") > -1) || (obj.add[3].indexOf("Circle") > -1) || (obj.add[3].indexOf("Street") > -1) || (obj.add[1].indexOf("Field") > -1))
    {puncthree = true;} else {puncthree = false;}
    Can be replaced by this - and return the same result:
    Code:
    if (obj.add[1].match( /(&|@|At|Circle|Street|Center|Field)/ ) ) {puncone = true;} else {puncone = false;}
    if (obj.add[2].match( /(&|@|At|Circle|Street|Center|Field)/ ) ) {punctwo = true;} else {punctwo = false;}
    if (obj.add[3].match( /(&|@|At|Circle|Street|Center|Field)/ ) ) {puncthree = true;} else {puncthree = false;}
    For some reason - that I can't quite logically work out in my head.. this way of searching a variable with many strings didn't work with indexOf(obj.myobject).. This seems like that same thing I was trying two posts ago... with the statecodes... But for some reason this is a different request.. Will have to stare at it until it hits me.. Of course any of you gurus can help me figure out HOW it's different..
    Last edited by NewdestinyX; 06-10-2014 at 04:10 PM.
    Here to help if I can. If I can't I know someone who can!

  21. The Following User Says Thank You to NewdestinyX For This Useful Post:

    RKO1195 (06-10-2014)

  22. #136
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Default The "FOR" Loop - Explanation/Application
    With Dacal's improvement to my code on my Google Location iWidget and more recently JunesiPhone's input on another thread I've taken to learning Loops. Loops are extremely helpful tools in coding to do otherwise repetitive tasks that glut of your code in viewing it and also are as resource efficient.

    There are 3 main Loops - the "FOR" loop, the "FOR/IN" loop and the "DO/WHILE" loop. The "FOR" loop is the one you'll see most in our iOS widget-type coding. And that's what I'll explain here.

    In a For loop you set a parameter of time in which a certain task or set of conditions (IF/THEN/ELSE) are applied to an array (which is a variable with numbers or strings of text in it).
    For a quick moment we have to speak about variables and objects to get them established in your code. I'm assuming you may already know this - but in case not....
    ---------------------------------------
    A regular Non-object Variable is set early in the code by:
    var MyVariable = ""; (which assigns the variable a 'blank' text)
    -or-
    var MyVariable; (which assigns the variable a 'null' status - meaning there's nothing in it at all)
    --explanation of the difference there is for another day....

    A Variable Array with more than 1 value or string of text in it is established with:
    var MyVariable = [""];


    An Object is established with:
    var obj = new Array; -- this will let you add different objects like obj.a, obj.b, etc..

    And then if you need an Object Array --> multiple objects within one object, it is established both at the beginning of your code with:
    var obj = new Array;
    and then, if it hasn't already been established earlier in your code, this goes right before your loop:
    obj.myObject = [];
    ---------------------------------------
    Now to the For loop.....
    In my code I have a task where I needed to look for the county name from within several of the objects in my object array called obj.add - which was populated with data from Google's xml formatted addresses.
    For a given set of coordinates Google was returning this data to my object array:
    obj.add[0] = 23 Belmont Ave, West Chester, PA 19382, USA (array positions always start with '0' in the code world)
    obj.add[1] = West Chester
    obj.add[2] = West Goshen
    obj.add[3] = Chester County
    obj.add[4] = Pennsylvania
    obj.add[5] = United States
    obj.add[6] = USA
    ----
    Now the county information returned from Google can be anywhere in positions [2] through [6] in the array. I create a new object (single, not an object array) called obj.county that could look for the country from within objects two through 6.

    THE LONG WAY to do that is:
    Code:
    if (obj.add[2].indexOf('County') > -1) {obj.county = obj.add[2];}
    else if (obj.add[3].indexOf('County') > -1) {obj.county = obj.add[3];}
    else if (obj.add[4].indexOf('County') > -1) {obj.county = obj.add[4];}
    else if (obj.add[5].indexOf('County') > -1) {obj.county = obj.add[5];}
    else if (obj.add[6].indexOf('County') > -1) {obj.county = obj.add[6];}
    Now my code was FULL of multiple line If/ELSE IF statements to test for a string of text (indexOf) or test for other things... BUT WATCH THE MAGIC of the FOR LOOP:
    Code:
    for (var i=2; i <=6; i++) {
    if (obj.add[i].indexOf('County') > -1) {obj.county = obj.add[i];}
    }
    HOW'S THAT FOR REDUCING redundancy?!?!
    My object array, obj.add, had already been established earlier in my code. That's why you didn't see " obj.add = []; " before my loop. Variables, Variable arrays, Objects and Object Arrays only need to be 'established' ONCE in your code. Most coders do this early in their .js file.

    So what's the loop doing, you ask?

    Within the () of the FOR syntax there are 3 items:
    var i=2 --> sets the starting place of loop and the position within the object array you want to start doing something. In my case - county is never in obj.add[0] or obj.add[1] - so we start at position '2' in the array..
    i <=6 --> this is how many times the loop will run -- it'll run for every position up to position [6] in the object array
    i++ --> this increments the loop by 1 until it reaches its max set in the second comman "i <=6".

    Then you set the instructions to do within the Curley Brackets { } - if my case I needed to test for the presence of the word 'county'.

    So: Where you'd normally place the 'number' position of the object array you replace that with the variable 'i'.
    Code:
    if (obj.add[i].indexOf('County') > -1) {obj.county = obj.add[i];}
    --- the loop and this 'if' test will ignore objects [2], [4], [5], [6] since they don't contain 'county' in the text and find the text string "County" in obj.add[3] and therefore the output will be: obj.county = "Chester County".

    No matter what position the 'county' was in - the loop will find it..

    This syntax removed at least 50 lines of code from my widget. LOL!! Love it!!

    There are likely many times when you'll want to search/test you entire Object Array for something in which case the For Loop's syntax would look like this:
    Code:
    for (var i=0; i < myObjectArray.length; i++) {
    ---tests or searches here--- 
    }//where myObjectArray is anything you've named your object array.
    //For my code that would read:  i < obj.add.length
    Enjoy the FOR LOOP!!!

    Thank you, Dacal & Thank you, June & Thank you, StackOverload.com and W3 Schools.com!!
    Last edited by NewdestinyX; 06-30-2014 at 08:14 AM.
    Here to help if I can. If I can't I know someone who can!

  23. The Following 3 Users Say Thank You to NewdestinyX For This Useful Post:

    Dacal (06-28-2014), King_O_Hill (06-29-2014), RKO1195 (06-28-2014)

  24. #137
    widget modder RKO1195's Avatar
    Join Date
    Aug 2010
    Location
    Alabama
    Posts
    2,326
    Thanks
    10,653
    Thanked 5,371 Times in 1,809 Posts

    Nice, I like reading this helps me out also

  25. The Following User Says Thank You to RKO1195 For This Useful Post:

    NewdestinyX (06-29-2014)

  26. #138
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Learned an important piece of code today... For removing duplicates in a variable array...

    If this were your array and you want to remove the extra 'james'
    var duplicatesArray = ['mike','james','james','alex'];

    Code:
     var uniqueArray = duplicatesArray.filter(function(elem, pos) {
        return duplicatesArray.indexOf(elem) == pos;
      });
    In this scenario your unique array will run through all of the values in the duplicate array. The elem variable represents the value of the element in the array (mike,james,james,alex), the position is it’s 0-indexed position in the array (0,1,2,3…), and the duplicatesArray.indexOf(elem) value is just the index of the first occurrence of that element in the original array. So, because the element ‘james’ is duplicated, when we loop through all of the elements in the duplicatesArray and push them to the uniqueArray, we are just pushing the James value twice, to the same position, in the uniqueArray - therefore the duplicate is overwritten, and the uniqueArray contains only unique values. -- Mike Heavers (http://mikeheavers.com/main/code-ite...ing_javascript)
    ----------------------

    Now.. let's look at application of it-- in my 'most advanced piece of coding to date.. (all done on my own ). I had a situation where when you're traveling 'in the sticks' Google's formatted address fields sometimes list 'other smaller towns' that are near the main town it's reporting. Sometimes 1 or even 2 other towns.. I thought the user of my widget would like to see this when there would otherwise be no other data to show on Line 2 (like with states that have no township or when you're not in a city with neighborhoods).. I'll highlight in red the ABOVE code strand in my application of it below..

    Code:
    /////////////////////////////////////////////
    ///MY PARSED DATA FROM GOOGLE/////
    obj.cityGO = Kingston, NY
    obj.add[1] = West Hurley
    obj.add[2] = West Hurley
    obj.add[3] = Hurley
    obj.add[4] = Kingston
    obj.add[5] = Ulster County
    obj.add[6] = New York
    obj.add[7] = USA
    /////////////////////////////////////////////
    
    //SEPARATE OUT TOWNS 'NEAR' to main town if any exist from Google data
    temp = [];
    temp1 = [];
    for (var i=1; i <=5; i++) {nearNear();}
    
    temp1 = temp.filter(function(elem, pos) {return temp.indexOf(elem) == pos;}); //remove any dupicates in array
    near = temp1.filter(function(e){return e}).join(" & ");//filters null data
    delete temp;
    delete temp1;
    	
    function nearNear () { /*test for towns near to main city*/
      if (
       (obj.add[i] != obj.cityGO)//not matching main city
       && (!obj.add[i].match(/(County|Parish|Region)/))//doesn't contain 'county/parish/region'
       && (states.indexOf(obj.add[i]) == -1)//not a state name
       && (cities.indexOf(obj.add[i]) == -1)//not a city name
       && (obj.add[i].indexOf(obj.xmlcountry) == -1)//not a country name
       && ( /^[^0-9&@]+$/i.test(obj.add[i]) )//no numbers, @ or & or -
      ) 
      { temp[i] = obj.add[i]; }//move all matches to 'temp' variable
    }
    Yields this in my Widget
    Kingston, NY
    near West Hurley & Hurley
    in Ulster County

    ( 41.995125, -74.089723 )
    Learning a lot fast...
    Last edited by NewdestinyX; 08-17-2014 at 12:18 PM.
    Here to help if I can. If I can't I know someone who can!

  27. The Following User Says Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (07-10-2014)

  28. #139
    ----NewD 2.0---- NewdestinyX's Avatar
    Join Date
    Jan 2012
    Posts
    9,814
    Thanks
    4,189
    Thanked 8,986 Times in 4,507 Posts

    Default The ! as a modifier in the 'match' syntax
    Another interesting piece of code all of us should have up our sleeves is simply the character " ! " (exclamation mark) which is an indicator of 'reversal' or 'not' something.. We all know it from != which means 'does NOT equal'.. But often certain syntaxes can accept this ! to reverse the way it works. Best example of this is the 'match' command - which up until I learned the reversing role of ! - I kept searching for a command that did the OPPOSITE of Match.. which is to return TRUE for an if/then when something DID NOT MATCH something else.. So let's look at the match command..
    Code:
    if  ( MyVariable.match(/( this | that | other )/ )  { do this  ;}
    In this syntax you are looking for a text strand within the variable or array called MyVariable. If it finds the words 'this', 'that' or 'other' - then it returns 'true' and executes the command between the curly brackets (do this). Upper or lower case doesn't matter in the 'match' command sequence there - but punctuation does. That's why I put a space before and after each word - to make sure it searches for separate words. If I had just put |this| then the word 'thistle' would have also returned TRUE to the if/then syntax.

    Now what's nice here - is that you do the 'opposite' search too by simply adding the ! (exclamation mark in front of the variable name. So:
    Code:
    if  ( !MyVariable.match(/( this | that | other )/ )  { do this  ;}
    ---this syntax now returns TRUE for ANY word that ISN'T/DOESN'T MATCH 'this', 'that' or 'other'.

    Handy little modifier, the ! ....

    Happy Coding!
    Grant
    Here to help if I can. If I can't I know someone who can!

  29. The Following 2 Users Say Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (08-17-2014), RKO1195 (08-17-2014)

  30. #140
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,291
    Thanks
    41,239
    Thanked 17,404 Times in 6,356 Posts

    Very nice explanation. I like how you spelled out the line of code in simple English that anyone can understand. Like "!=" reads "not equal to". This is something that most tutorials just take it that you know this already. Makes it a lot easier for the beginner to follow and understand. I laugh because that's typically all I needed to learn code was for someone to just read me the literal translation. Keep up the good work.
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  31. The Following User Says Thank You to King_O_Hill For This Useful Post:

    RKO1195 (08-17-2014)

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts