Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by HBS_JohnnyC · Apr 24, 2015 at 07:46 PM · stringconvert

Pulling the first two characters from a string. Code not working.

         WWW cityRequest = new WWW("http://www.geoplugin.net/json.gp?ip="+ currentIP); //get player location
         yield return cityRequest;
         var N = JSON.Parse(cityRequest.text);
         currentCity = N["geoplugin_city"].Value;
         currentCountry = N["geoplugin_countryName"].Value;
         currentLon = N["geoplugin_latitude"].Value;
         currentLat = N["geoplugin_longitude"].Value;
         string shortLon = currentLon.Substring(0,2);
         string shortLat = currentLat.Substring(0,2);

It looks like it would work and from what I google it should but when I actually put it into practice but when I run the program I get nothing.

currentLon: 23.43924*
currentLat: 58.23423
shortLon:
shortLan:

alt text

*do note this just random numbers and not the actual numbers that was generated by my program.

EDIT: Added image that shows issue.

unityquestion.png (13.5 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HBS_JohnnyC · Apr 24, 2015 at 07:49 PM 0
Share

No that is why I am confused, I don't get any errors it just doesn't give a value when running it on unity. I'll try to get a picture so it'll be more clear.

avatar image HBS_JohnnyC · Apr 24, 2015 at 08:09 PM 0
Share

Okay I feel really silly relative to how much work I put into solving it.

The solution is there is no problem. It just doesn't show up on the inspector for some reason but if I actually draw it onto the game screen it shows up.

Despite all my messing around in the code, I have no idea why I never tried that.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hangemhigh · Apr 24, 2015 at 08:25 PM

Maybe WWW is not done before you accessed it. Try this

 WWW cityRequest;
 
     // Use this for initialization
     void Start ()
     {
         StartCoroutine(getCityInfo());
     }
     
     // Update is called once per frame
     void Update ()
     {
         if(cityRequest.isDone){
             showResult();
         }
     }
 
     IEnumerator getCityInfo(){
     cityRequest = new WWW ("http://www.geoplugin.net/json.gp?ip=" + currentIP); //get player location
         //Wait until the info is done receing bytes
         while(!cityRequest.isDone){
             yield return null;
         }
     }
 
     void showResult(){
         if(cityRequest != null && cityRequest.isDone){
             var N = JSON.Parse (cityRequest.text);
             currentCity = N ["geoplugin_city"].Value;
             currentCountry = N ["geoplugin_countryName"].Value;
             currentLon = N ["geoplugin_latitude"].Value;
             currentLat = N ["geoplugin_longitude"].Value;
             string shortLon = currentLon.Substring (0, 2);
             string shortLat = currentLat.Substring (0, 2);
         }
     }

Or maybe you have trailing characters in the string. Use shortLon.Trim() and shortLat.Trim() to remove the leading and trailing white space then try the Substring function again.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

c# convert int to string 2 Answers

Converting String to a Game Object 1 Answer

Convert string to float or double - errors 1 Answer

Convert GameObject to String? 2 Answers

Array - Convert Object into Int 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges