Letter-cases

What would you like to see in CSPro?
arkagwa
Posts: 108
Joined: November 18th, 2014, 5:25 am

Letter-cases

Postby arkagwa » September 3rd, 2018, 12:08 pm

Dear developers

The current feature allows two cases for letters; lower letters and upper/capital letters. Sometimes the variable captures three names or two words where you need the initials with capital letters, example Andrew Raphael,....Letters A and R (initials) are capital. This feature is missing

If there is alternative solution kindly help, i find it difficult for data entrants switching cases in keyboard :( :(

Good evening

josh
Posts: 1866
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Letter-cases

Postby josh » September 4th, 2018, 6:27 am

Why not just tell the enumerators to use all lower case or all upper case? You can convert to mixed in case in logic if you really need it although in many cases it is not needed. To convert to mixed case just have a loop through the string and each time you find a space you capitalize the next letter.

arkagwa
Posts: 108
Joined: November 18th, 2014, 5:25 am

Re: Letter-cases

Postby arkagwa » January 8th, 2019, 12:55 am

Dear Josh

Can you assist me with the code for looping the string to capitalize every first letter.......please i would appreciate very much :) :)

josh
Posts: 1866
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Letter-cases

Postby josh » January 8th, 2019, 6:10 am

Try Googling "capitalize first character of each word in string". That will show you some examples in other programming languages that you can adapt to CSPro.

htuser
Posts: 382
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: Letter-cases

Postby htuser » January 11th, 2019, 2:41 pm

Hi Josh,
I find this code for the same purpose:

Code: Select all

#include <stdio.h>
#define MAX 100

int main()
{
   char str[MAX]={0};   
   int i;
   
   //input string
   printf("Enter a string: ");
   scanf("%[^\n]s",str); //read string with spaces
   
   //capitalize first character of words
   for(i=0; str[i]!='\0'; i++)
   {
      //check first character is lowercase alphabet
      if(i==0)
      {
         if((str[i]>='a' && str[i]<='z'))
            str[i]=str[i]-32; //subtract 32 to make it capital
         continue; //continue to the loop
      }
      if(str[i]==' ')//check space
      {
         //if space is found, check next character
         ++i;
         //check next character is lowercase alphabet
         if(str[i]>='a' && str[i]<='z')
         {
            str[i]=str[i]-32; //subtract 32 to make it capital
            continue; //continue to the loop
         }
      }
      else
      {
         //all other uppercase characters should be in lowercase
         if(str[i]>='A' && str[i]<='Z')
            str[i]=str[i]+32; //subtract 32 to make it small/lowercase
      }
   }
   
   printf("Capitalize string is: %s\n",str);
   
   return 0;
}


And it seem difficult to port it to Cspro Programming Language... I can't "translate"
#define MAX 100
scanf("%[^\n]s",str); //read string with spaces
char str[MAX]={0};
str[i]!='\0';


Please can you help us?

In the future when we can use C/C++ functions/methods/classes inside Cspro Logic, this will open an univers for Csprousers.

Thanks in advance!

josh
Posts: 1866
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Letter-cases

Postby josh » January 11th, 2019, 5:04 pm

You don't need the scanf part. That part is reading the string that user types in. The important part starts from the for loop.

htuser
Posts: 382
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: Letter-cases

Postby htuser » January 11th, 2019, 10:55 pm

Hi Josh,
I'm trying to port this code and here's the results...with errors...
Please, can you help me to correct!

Thanks in advance,

CapitalizeString.zip
(2.65 KiB) Downloaded 44 times

Gregory Martin
Posts: 1184
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Letter-cases

Postby Gregory Martin » January 12th, 2019, 3:29 pm

Your code does some things it doesn't need to like use \0, which is not needed in CSPro. You can write this logic pretty simply using CSPro functions:

function string capitalizeEachWord(string text)

    numeric next_non_blank_letter_should_be_capitalized = 1;

    do numeric ctr = 1 while ctr <= length(text)

        string this_letter = text[ctr:1];

        if this_letter = " " then
            next_non_blank_letter_should_be_capitalized = 1;

        elseif next_non_blank_letter_should_be_capitalized = 1 then
            text[ctr:1] = toupper(this_letter);
            next_non_blank_letter_should_be_capitalized = 0;

        else
            text[ctr:1] = tolower(this_letter);

        endif;

    enddo;

    capitalizeEachWord = text;

end;

htuser
Posts: 382
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: Letter-cases

Postby htuser » January 13th, 2019, 2:49 pm

Thank you Greg. Since Cspro have powerful functions, i had to think in Cspro, not trying to "translate".
Best Regards,

arkagwa
Posts: 108
Joined: November 18th, 2014, 5:25 am

Re: Letter-cases

Postby arkagwa » January 19th, 2019, 1:49 pm

Does not work for me ...keep asking for ; operator
Is word "text" a syntax or used as variable??


Return to “Feature Requests”