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

  • Home
  • SEARCH
  • 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 3842216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:45:42+00:00 2026-05-19T15:45:42+00:00

i have a string with string length of 56. First i tried to make

  • 0

i have a string with string length of 56.

First i tried to make sure, that the string hast the right length, if not, the app should fill several labels with other content.

if ([[NSString stringWithContentsOfURL:siteURL] length] == 56) {

    NSString *siteString = @"http://www.xxxx/iphone.txt";   
    NSURL *siteURL  = [NSURL URLWithString:siteString];
    myField2.text = [NSString stringWithContentsOfURL:siteURL encoding:NSUTF8StringEncoding error:nil]; 
    [NSString stringWithContentsOfURL:siteURL encoding:NSUTF8StringEncoding error:nil];
    NSArray *myArray = [[NSString stringWithContentsOfURL:siteURL encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString: @":  "];


    [myField2 setText: [myArray objectAtIndex: 0]];
    [myField3 setText: [myArray objectAtIndex: 1]]; 
    [myField4 setText: [myArray objectAtIndex: 2]];
    [myField5 setText: [myArray objectAtIndex: 3]];
    [myField6 setText: [myArray objectAtIndex: 4]];


}
else {

    [myField2 setText: @"-"];
    [myField3 setText: @"-"];   
    [myField4 setText: @"-"];
    [myField5 setText: @"-"];
    [myField6 setText: @"-"];
}

In my string there are usually 28 numbers.
I want my app to check the string, wether there are 28 numbers or not.
I tried to use the following code:

for (int number = 0; number = 28; number++) {

}

But i guess that is not the right way.

I have a given range, 56, and possible numbers 0-9, any ideas how the code has to look like?

Thanks in advance 🙂

Well i tried it:

for (int number = 0; number < 56; number++){
    unichar c = [[NSString stringWithContentsOfURL:siteURL] characterAtIndex:number];

    if (c >= '0'  &&  c <= '9'){
        number++;

        if (number = 28) {
            NSString *siteString = @"http://www.xxxx/iphone.txt";   
            NSURL *siteURL  = [NSURL URLWithString:siteString];
            myField2.text = [NSString stringWithContentsOfURL:siteURL encoding:NSUTF8StringEncoding error:nil]; 
            [NSString stringWithContentsOfURL:siteURL encoding:NSUTF8StringEncoding error:nil];
            NSArray *myArray = [[NSString stringWithContentsOfURL:siteURL encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString: @":  "];


            [myField2 setText: [myArray objectAtIndex: 0]];
            [myField3 setText: [myArray objectAtIndex: 1]]; 
            [myField4 setText: [myArray objectAtIndex: 2]];
            [myField5 setText: [myArray objectAtIndex: 3]];
            [myField6 setText: [myArray objectAtIndex: 4]];
        }

        else {
            [myField2 setText: @"-"];
            [myField3 setText: @"-"];   
            [myField4 setText: @"-"];
            [myField5 setText: @"-"];
            [myField6 setText: @"-"];

        }

}
}

But it doesn’t work, i guess i made some mistakes 😡

current code:

int i = 0; 

for (int numberc = 0; numberc < 56; numberc++){ 
    unichar c = [[NSString stringWithContentsOfURL:siteURL encoding:NSASCIIStringEncoding error:&error] characterAtIndex:numberc]; 

    // Funktion die bestimmt, dass bei jedem positiven Match der Zähler um eins erhöht wird.    
    if (c >= '0'  &&  c <= '9'){ //Parameter für das Absuchen des Strings
        i++;
    }
}
  • 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-05-19T15:45:43+00:00Added an answer on May 19, 2026 at 3:45 pm

    Your for loop will need to go along the length of the string. e.g.

    int nLength = [myString length];
    for (int number = 0; number < nLength; number++)
    

    Then you will want to get a single character from that string. Use the characterAtIndex method.

    unichar c = [myString characterAtIndex:number];
    

    Then check for that character being between ‘0’ and ‘9’. e.g.

    if (c >= '0'  &&  c <= '9')
    

    EDIT: Additional notes regarding the comments.
    To count the numbers, start an integer at zero, before the for loop:

    int numbercount = 0;
    

    Inside the test for the character being numeric, increment it there:

    if (c >= '0'  &&  c <= '9')
    {
        numbercount++;
    

    Test for it being 28. Note the == for comparison:

    if (numbercount == 28)
    

    EDIT: Additional notes for next comment

    int i = 0;
    NSString *url = [NSString stringWithContentsOfURL:siteURL encoding:NSASCIIStringEncoding error:&error];
    
    for (int numberc = 0; numberc < 56; numberc++)
    {
        unichar c =  [url characterAtIndex:numberc];
    
        // Funktion die bestimmt, dass bei jedem positiven Match der Zähler um eins erhöht wird.
        if (c >= '0'  &&  c <= '9')
        {
            //Parameter für das Absuchen des Strings         
            i++;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.