Advertisement

How can I do this (strings).

Started by December 25, 2000 03:39 AM
4 comments, last by Quantum 24 years, 1 month ago
Say I have a string called String1 of a fixed size which contains "1 2 3" and a string called String2 also of a fixed size. What I want to do is copy the contents of String1 into String2, but replace '1' with "one", '2' with "two", etc. It's simple to replace it with one character, but if I do something like: String2 = 'o'; String2 = 'n', etc. then parts will be overwritten. So do I need to move it all along or what? Sorry if this is a bit vague, but I have no idea how to do this. Thanks <img src="smile.gif" width=15 height=15 align=middle> Edited by - Quantum on 12/25/00 3:41:21 AM
I think u better use pre-defined array of definitions of numbers like this:
dim String1 as String
dim String2 as String

get string1 from user

then u say to use that the max number is such( say, 10000):
if len(string1)>=6 then message to user that "number is to big"
else
select case len(string1)

case is =1
call FirstDigit
case is =2
call SelectDigit
case is =3
call ThirdDigit
case is =4
call FourthDigit
case is =5
Call FifthDigit
end select

ur firstdigit..
Public Sub First Digit()
''define ur array of first digits as
dim FirstDigits(0 to 9) as string
firstdigits(0)="Zero"
firstdigits(1)="one"
and so on
end sub

Public Sub Second Digit( )
dim SecondDigits(0 to 9) as string
seconddigits(0)="ten"
seconddigits(1)="eleven"
and so on till "nineteen"
select case left(string1,1)
case is = "2"
string2="Twenty" & firstdigit(val(left(string1,2)))
case is ="3"
string2="Thirty" & firstdigit(val(left(string1,2)))
case is = "4"
string2="Fourty" & firstdigit(val(left(string1,2)))
and so on until 9
end select
end sub


Public Sub Third Digit( )
select case left(string1,1)
case is ="1"
string2= firstdigit(val(left(string1,1))) & "Hundred" & SecondDigit(val(right(left(string1,2),1))
case is = "2"
string2= firstdigit(val(left(string1,1))) & "Hundred" & SecondDigit(val(right(left(string1,2),1))

end select
end sub


Public Sub Fourth Digit( )

end sub

Public Sub Fifth Digit()

end sub


And so on.. u get the idea? )
Advertisement
Um, sorry, I should have mentioned I was trying to do this in C++. VB looks completely alien to me too
And I''d rather not resort to using standard string types if I can.
Hope this is what you mean,
if str1 contains "1 2 5 1 6 7", then
str2 will containt "one two five one six seven".

  void numericToStr(const char str1[], char str2[]){  int i = strlen(str1);  strcpy(str2,"");  while (i<len)  {    switch(str1<i>)    {      case '1': strcat(str2,"one "); break;      case '2': strcat(str2,"two "); break;      case '3': strcat(str2,"three "); break;      case '4': strcat(str2,"four "); break;      case '5': strcat(str2,"five "); break;      case '6': strcat(str2,"six "); break;      case '7': strcat(str2,"seven "); break;      case '8': strcat(str2,"eight "); break;      case '9': strcat(str2,"nine "); break;      case ' ': strcat(str2," ");     }    i++;      }}void main(){  char myNumbers[] = "1 6 1 5 6";  char alphaStr[50];    // copy and convert  numericToStr(myNumbers,alphaStr);}  



Hope this helped

/ Tooon


Edited by - Tooon on December 25, 2000 7:00:09 PM

Edited by - Tooon on December 25, 2000 7:01:59 PM
Tooon, thank you so much!
Exactly what I wanted

Edited by - Quantum on December 25, 2000 8:45:36 PM

This topic is closed to new replies.

Advertisement