Registreer FAQ Berichten van vandaag


Ga terug   Scholieren.com forum / Technologie / Software & Hardware
Reageren
 
Topictools Zoek in deze topic
Oud 16-03-2003, 13:09
AtOx
Avatar van AtOx
AtOx is offline
Heyz,

Ik ben met 'iets' bezig en daarvoor moet ik integers omzetten in string. Dus getallen naar letters.

Heeft iemand hier een lijst van of een programma voor?

Much greetz,
Atoxje
__________________
De enige helpende hand vind ik aan het einde van m'n mouw...HIP: zopje, BlackButterfly, Liltje ,JoJoz,BadlyDrawnGirl,********, ....Mema mn vrouwtjuh
Met citaat reageren
Advertentie
Oud 16-03-2003, 13:11
Talon
Avatar van Talon
Talon is offline
in C:

itoa(x,y,10);

?
__________________
Napoleon, don't be jealous that I've been chatting online with babes all day | Ugh! Gross! Freakin' idiot!

Laatst gewijzigd op 16-03-2003 om 13:15.
Met citaat reageren
Oud 16-03-2003, 13:14
niemand
Avatar van niemand
niemand is offline
Citaat:
AtOx schreef op 16-03-2003 @ 14:09:
Heyz,

Ik ben met 'iets' bezig en daarvoor moet ik integers omzetten in string. Dus getallen naar letters.

Heeft iemand hier een lijst van of een programma voor?

Much greetz,
Atoxje
het is ook altijd handig om te weten of je in c of in assembly progt..
en wil je dan dat een int met waarde 12345 omgezet word naar een string met waarde "12345" ?
Met citaat reageren
Oud 16-03-2003, 13:36
CryptapiX
Avatar van CryptapiX
CryptapiX is offline
beetje heel rare vraagstelling
meer info over welke taal zou niet overbodig zijn
__________________
I have not failed, I have just found 10.000 ways that won't work
Met citaat reageren
Oud 16-03-2003, 15:25
Verwijderd
IntToStr(); ???
Over welke taal heb je het?
Met citaat reageren
Oud 16-03-2003, 15:57
* ^_^ *
* ^_^ * is offline
Code:
#!/usr/bin/env python
 
### 
# Title: Type Checking 
# Author: Ben Briggs @ linuxnewbie.org 
# Date: March 28, 2001 
# Written for: CCAE http://www.codeexamples.org 
# Description: 
# Illustraits how to check for the types 
# of objects. 
###
 
### 
# This line imports all the objects in the 
# module 'types' without object-oriented 
# programming. For example, using the import 
# method, to use the object type 'IntType', 
# you'd need to type 'types.IntType'. With 
# the 'from/import' method, you just need 
# to type 'IntType'. 
###
from types import IntType
 
### 
# Now begins the normal module importation 
# section. 
###
import string  # atoi()
import readline  # Enable 'history' of previously entered values (Use up arrow)

def main():
     ###
     # Variable declarations.
     # ----------------------
     # The variable named 'num' will initially defined
     # with the value of '10000', this will kick off
     # the Number to String/String to Number conversions.
     ###
    num = 10000
    
     ###
     # 'stringspace' will be used throughout the program
     # for converting numbers to strings, and storing
     # other strings.
     #
     # The builtin function 'str()' converts the argument
     # given into a string and returns the new string value.
     ###
    stringspace = str(num)
    print "num: %d  stringspace: %s" % (num, stringspace)

     ###
     # Now perform the number conversion on a literal,
     # as opposed to a variable.
     ###
    stringspace = str(5007)
    print "num: %d  stringspace: %s" % (num, stringspace)

     ###
     # This next line uses the 'atoi()' method of the
     # string module, to convert the string back to a
     # number.
     ###
    num = string.atoi(stringspace)
    print "num: %d  stringspace: %s" % (num, stringspace)

     ###
     # The code in this 'try' statement will assign the
     # string 'good pizza' to the string variable 'stringspace'
     # if the attempt is insuccessful, Python will print
     # an error message stating that it cannot make the
     # conversion.
     ###
    try:
        stringspace = "good pizza"
        num = string.atoi(stringspace)
    except ValueError:
         ###
         # If the buildin exception 'ValueError' happens,
         # print this block of code. A 'ValueError' is
         # storing an inappropriate type in a variable,
         # like assigning a string to an integer.
         ###
        print "Could not convert data to and integer."

     ###
     # Print the values again, to see what is stored in
     # 'num' when the conversion fails.
     ###
    print "num: %d  stringspace: %s" % (num, stringspace)

     ###
     # This 'if' statement checks to see if 'stringspace'
     # was converted to an integer, if it was... print
     # a message stating the new value. If the conversion
     # failed specify that the value in 'stringspace' is
     # a string, and therefore cannot be converted to a
     # integer. This is check with the type 'IntType' from
     # the 'types' module imported at the top of the script.
     ###
    if stringspace is IntType:
        num = string.atoi(stringspace)
        print "new num: %d" % num
    else:
        print "%s is not a number" % stringspace

    print  # A newline is printed
     ###
     # The user is prompted to enter a number.
     ###
    print "Please enter a number at the prompt. Hit enter on a blank line to 
exit."

     ###
     # This 'while' loop runs while 'stringspace'
     # is not an empty string (result of pressing
     # the Enter/Return key without entering text).
     ###
    while stringspace != '':
         ###
         # A prompt is printed using the builtin
         # function 'raw_input()', the text passed
         # as a argument, will be printed at the prompt.
         # Any text entered at this prompt, will be
         # stored in the variable 'stringspace'.
         ###
        stringspace = raw_input("> ")
         ###
         # If any text was entered, Python runs
         # the code in this 'if' statement. If not...
         # a "Good Bye" message is printed, and the program
         # exits.
         ###
        if stringspace != '':
             ###
             # This 'try' statement attempts to convert
             # the value(s) entered at the prompt into
             # an integer. If the conversion is successful,
             # Python will print a message stating that the
             # text was a number. If there is a 'ValueError',
             # Python will print that the text is a string.
             ###
            try:
                num = string.atoi(stringspace)
                print "%d is a number." % num
            except ValueError:
                print "%s is a string" % stringspace
        else:
            print "Good Bye!"
 
### 
# The next two lines of code check to 
# see if this script is being loaded 
# as a module, or directly being executed. 
# If the answer is the latter, execute the 
# main() function. 
###
if __name__ == '__main__':
    main()
Met citaat reageren
Oud 16-03-2003, 19:35
LB06
LB06 is offline
In JAVA moet je het met de methode valueOf() doen.

Code:
int cijfers = 14;
String tekens = String.valueOf(tekens);
En je hebt de int geconverteerd naar een string

Laatst gewijzigd op 17-03-2003 om 14:35.
Met citaat reageren
Oud 16-03-2003, 19:50
niemand
Avatar van niemand
niemand is offline
Citaat:
LB06 schreef op 16-03-2003 @ 20:35:
In JAVA moet je het met de methode valueOf() doen.

Code:
int cijfers = 14
string tekens = String.valueOf(tekens)
En je hebt de int geconverteerd naar een string
en die code weigert ie
het type 'string' bestaat namelijk niet, het is 'String'
daarnaast vergeet je 2x een puntkomma
en ja, met die fouten weigert ie gewoon

daarnaast kan het ook een stuk korter:

Code:
int cijfers = 14;
String tekens = ""+cijfers;
Met citaat reageren
Oud 16-03-2003, 21:20
TouchOfDarkness
Avatar van TouchOfDarkness
TouchOfDarkness is offline
Citaat:
niemand schreef op 16-03-2003 @ 20:50:
en die code weigert ie
het type 'string' bestaat namelijk niet, het is 'String'
daarnaast vergeet je 2x een puntkomma
en ja, met die fouten weigert ie gewoon

daarnaast kan het ook een stuk korter:

Code:
int cijfers = 14;
String tekens = ""+cijfers;
volgens mij is dat laatste wel een heel lelijke oplossing...
__________________
He can't hear the sirens, cause silence is the greatest sleep of them all.
Met citaat reageren
Oud 16-03-2003, 21:26
niemand
Avatar van niemand
niemand is offline
Citaat:
TouchOfDarkness schreef op 16-03-2003 @ 22:20:
volgens mij is dat laatste wel een heel lelijke oplossing...
wat is er mis mee?
dat is de manier waarop ik op de hva leer om een int om te zetten naar een string
Met citaat reageren
Oud 17-03-2003, 09:51
Marcade
Avatar van Marcade
Marcade is offline
Hallo zeg wat een bs. hier; die vent heeft niet eens gezegd welke taal.
Met citaat reageren
Oud 17-03-2003, 12:43
dafelix
Avatar van dafelix
dafelix is offline
hehe. anyway mocht je in VB progameeren:

IntegerName = CStr(StringName)

de niet officiele manier:

Dim IntegerName As Integer
Dim StringName As String

IntegerName = StringName



Maar voortaan issut wel makkelijk als je bijzet welke taal je programmeert, ik heb dit nu waarsgijnlijk voor nix zitten typen
__________________
$karma++;
Met citaat reageren
Oud 17-03-2003, 14:37
LB06
LB06 is offline
Citaat:
niemand schreef op 16-03-2003 @ 20:50:
en die code weigert ie
het type 'string' bestaat namelijk niet, het is 'String'
daarnaast vergeet je 2x een puntkomma
en ja, met die fouten weigert ie gewoon

daarnaast kan het ook een stuk korter:

Code:
int cijfers = 14;
String tekens = ""+cijfers;
Srry. Heb het ge-edit. Had iid wel iets zorgvuldiger mogen zijn.
Met citaat reageren
Oud 17-03-2003, 17:27
TouchOfDarkness
Avatar van TouchOfDarkness
TouchOfDarkness is offline
Citaat:
niemand schreef op 16-03-2003 @ 22:26:
wat is er mis mee?
dat is de manier waarop ik op de hva leer om een int om te zetten naar een string
nou ja, het werkt op zich wel, maar ik vind het geen mooie oplossing. Ben meer voorstander van explicit casting in dit geval, omdat daarmee veel duidelijker aangegeven wordt wat er precies gebeurt.
__________________
He can't hear the sirens, cause silence is the greatest sleep of them all.
Met citaat reageren
Advertentie
Reageren


Regels voor berichten
Je mag geen nieuwe topics starten
Je mag niet reageren op berichten
Je mag geen bijlagen versturen
Je mag niet je berichten bewerken

BB code is Aan
Smileys zijn Aan
[IMG]-code is Aan
HTML-code is Uit

Spring naar

Soortgelijke topics
Forum Topic Reacties Laatste bericht
Huiswerkvragen: Exacte vakken [INF]Help gezocht (Visual Basic)
Lothar
21 14-04-2008 21:24
Software & Hardware Delphi en text bestanden
BendeBen
2 25-01-2007 18:42
Software & Hardware getallenstelsels in visual basic.net
Land_of_spirits
25 25-09-2006 17:16
Software & Hardware [Prog] Delphi: carpool-programma
whgeraards
12 21-06-2005 12:39
Software & Hardware [Alg] Veilig (web)programmeren
Dr HenDre
9 12-04-2005 01:29


Alle tijden zijn GMT +1. Het is nu 11:44.