473,228 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

reading only the last number from i.e. "1234" (4 that will be)

as 1st, sorry on my clumsy english (now I realy miss some words)

I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:

1 slikU
2 slikE
3 slikE
4 slikE
5 slikA
6 slikA
7 slikA
....
20 slikA
21 slikU
22 slikE
23 slikE
24 slikE
25 sliKA
....
99 slikA
100 slikA
101 slikU
102 slikE...

so that is pattern:
all numbers which ends with 1 need to have "U",
2-4 = "E"
5-x0 = "A"

and question: how to read only the last number from count(*) ?

--
Jan ko?
http://fotozine.org
--
Jul 17 '05 #1
4 1907
.oO(JaNE)
I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:
[...]

so that is pattern:
all numbers which ends with 1 need to have "U",
2-4 = "E"
5-x0 = "A"

and question: how to read only the last number from count(*) ?


I would do it differently. The pattern is always the same, so it's quite
easy to just devide the number by 10 and have a look at the remainder
(modulo operation), e.g.

$number = 22;
$foo = array('a', 'u', 'e', 'e', 'e', 'a', 'a', 'a', 'a', 'a');
print $foo[$number % 10];

will print 'e'.

The array $foo contains the chars for 0, 1, 2, ... , 9. The expression

$number % 10

calculates the remainder when deviding the number by 10, which is then
used as an index in the char array.

HTH
Micha
Jul 17 '05 #2
JaNE wrote:
as 1st, sorry on my clumsy english (now I realy miss some words)

I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:

1 slikU
2 slikE
3 slikE
4 slikE
5 slikA
6 slikA
7 slikA
...
20 slikA
21 slikU
22 slikE
23 slikE
24 slikE
25 sliKA
...
99 slikA
100 slikA
101 slikU
102 slikE...

so that is pattern:
all numbers which ends with 1 need to have "U",
2-4 = "E"
5-x0 = "A"

and question: how to read only the last number from count(*) ?

You could also do a typeconversion:

$str = (string) $num;
$lastchar = $str [strlen($str)-1];

followed by an if/else or a switch/case statement, or a lookup using the
reconverted char in a predefined string/array with all the appropriate
characters/strings.

You may omit the explicit conversion, but it is not good coding practice.

Using modulo as offered by others is probably the neater, quicker and
more correct approach I admit. The latter bit (the lookup) can be used
in the modulo approach very well too.

Schraalhans.
Jul 17 '05 #3
"JaNE" <no****@mail.dot> wrote in message
news:1gqjgxv.1jlgn2h13rc8wqN%no****@mail.dot...
as 1st, sorry on my clumsy english (now I realy miss some words)

I have one language specific problem with my site. I would like to tell
how meny pictures someone have in his or her gallery and I would like to
have it properly speled (in Croatian). So, I don't want to write:
"number of pitures in this gallery: 123" rather "John have 123
pictures"... but, here is my problem, I will write now some little
Croatian with differences in capital letters:


Use the % operator to get the remainder after a division:

5 % 10 == 5
15 % 10 == 5
135 % 10 == 5
1234 % 10 == 4

For the word endings, you probably want to write a function since the logic
can get quite complicated. And it's something you'd use often.

An example:

function k($num) {
if($num >= 10 && $num <= 19) {
return 'a';
}
$mod = $num % 10;
if($mod == 1) {
return 'u';
}
else if($mod >= 5) {
return 'a';
}
else {
return 'e';
}
}

I'm guessing here that it's "0 slika" and not "0 sliku".

For those who don't understand what the problem is: the OP wants to print
the correct word ending for a given number of objects. In English, we have
"1 picture" but "2 pictures". In Slavic languages this is much more
complicated. 1 is singular; 2, 3, and 4 are plural; 5 and above need a
different declension (4 pictures, but 5 of pictures). The final digit
determines the ending (24 pictures, 25 of pictures), which is why the
modulus of 10 is taken. The exceptions are 10 - 19.
Jul 17 '05 #4
Chung Leong wrote:
<snip>
I'm guessing here that it's "0 slika" and not "0 sliku".

For those who don't understand what the problem is: the OP wants to print the correct word ending for a given number of objects. In English, we have "1 picture" but "2 pictures". In Slavic languages this is much more
complicated. 1 is singular; 2, 3, and 4 are plural; 5 and above need a different declension (4 pictures, but 5 of pictures). The final digit
determines the ending (24 pictures, 25 of pictures), which is why the
modulus of 10 is taken. The exceptions are 10 - 19.


Oh cool:) Chung knows Croatian too...

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: William Morris | last post by:
Apologies in advance for the cross-post. Not sure if this is better handled in ASP code or TransactSQL. Windows2000 Server SQL 2000 tblPeople contactid int firstname varchar(25) lastname...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
43
by: markryde | last post by:
Hello, I saw in some open source projects a use of "!!" in "C" code; for example: in some header file #define event_pending(v) \ (!!(v)->vcpu_info->evtchn_upcall_pending & \...
7
by: fakeprogress | last post by:
For a homework assignment in my Data Structures/C++ class, I have to create the interface and implementation for a class called Book, create objects within the class, and process transactions that...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
0
barbk
by: barbk | last post by:
Hey all, In DB2 v9 is it possible to have an auto generated number field within a primary key that is a combination of multiple fields? For example resv locn sale_no 1234 789...
2
by: arnuld | last post by:
i am confused on some aspects of bitset class: /* C++ Primer 4/e * chapter 3 * * exercise 3.23 * */ #include <iostream>
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.