Communauté Informatique NDFR.net : delete the second character of a string? - Programmation (C/C++, Delphi, VB, etc.)
Reply
delete the second character of a string?
Thread Tools Display Modes
  #1  
Old 28-01-2004, 16:42
batteur91 batteur91 is offline
Membre junior
 
Join Date: 28-01-2004
Posts: 3
Question delete the second character of a string?

Hi all,
I'm looking for a solution to retrieve ( or copy) the second character of a string.
My program is:
int iNum=0;
char sNum[2]="";
//Somewhere in the program, the integer iNum=92
// Then
sprintf (sNum,"%d",iNum);
And I want to delete the first character of the string sNum, but i don't know how can i do?
Or I want to retrieve the second character of the string sNum which is the value '2' in order to put it to another string, but i don't know how can i do?

In sumarize, I want that sNum="2"; or another string ="2"; I don't want to get the whole value iNum. I only want the last value of it.
Thanks for your help
Bye
batteur91
Reply With Quote
  #2  
Old 28-01-2004, 17:22
Matt Matt is offline
Super modérateur
1 Highscore
 
Join Date: 24-12-2002
Posts: 4,453
Re : delete the second character of a string?

1) You are on a FRENCH forum !!!

2) When you write in english, please try to use correct english grammar and syntax ...
Reply With Quote
  #3  
Old 28-01-2004, 17:49
Spycam's Avatar
Spycam Spycam is offline
Spectre de ces lieux
 
Join Date: 25-10-2002
Location: France
Age: 36
Posts: 1,075
Re : delete the second character of a string?

And what is the language ? C++ ?
Reply With Quote
  #4  
Old 28-01-2004, 18:02
batteur91 batteur91 is offline
Membre junior
 
Join Date: 28-01-2004
Posts: 3
Re : delete the second character of a string?

I use the C language.
Reply With Quote
  #5  
Old 28-01-2004, 18:42
Cougar's Avatar
Cougar Cougar is offline
Membre senior
 
Join Date: 16-09-2001
Location: Orléans
Age: 39
Posts: 3,850
Send a message via MSN to Cougar
Re : delete the second character of a string?

Code:
 
main()
{
char sNum[1],res;
/*sNum = "bo"*/
sNum[0]='b';
sNum[1]='o';
/* res is the second character of sNum*/
res=sNum[1];
 
}
__________________

Last edited by Cougar; 28-01-2004 at 18:54.
Reply With Quote
  #6  
Old 28-01-2004, 20:53
batteur91 batteur91 is offline
Membre junior
 
Join Date: 28-01-2004
Posts: 3
Re : delete the second character of a string?

thanks but, this is not enough,
In my program, sNumis eqaul to "64" for example(a numeric value).
sNum is a variable; that means it's gonna change during the execution. So I only can declare the variable sNum at the beginning of my program. I can't declare it as you did below. (sNum[0]='b' and sNum[1]='o').
main()
{
char sNum[1],res;
/*sNum = "bo"*/
sNum[0]='b';
sNum[1]='o';
/* res is the second character of sNum*/
res=sNum[1];

}
Reply With Quote
  #7  
Old 28-01-2004, 20:58
Cougar's Avatar
Cougar Cougar is offline
Membre senior
 
Join Date: 16-09-2001
Location: Orléans
Age: 39
Posts: 3,850
Send a message via MSN to Cougar
Re : delete the second character of a string?

sNum = "what you want when you want where you want"

to get the n-ième char of a string you do : sNum[n-1]

for exemple, if sNum is "to" ,you declare a char (here res) and you write res=sNum[1] to get the second character of the string...

Or use a int instead of string and do (name_of_int)%10 to get the unit of the integer.
__________________
Reply With Quote
  #8  
Old 28-01-2004, 21:01
Matt Matt is offline
Super modérateur
1 Highscore
 
Join Date: 24-12-2002
Posts: 4,453
Re : delete the second character of a string?

Bon, batteur, au lieu de t'emmerder à écrire un espèce d'anglais digne d'un gamin de 6ème qui débute, écrit français ... Parce que j'ai vraiment du mal à croire que t'es pas francophone (ton anglais est plein de gallicisme, et ton pseudo fait quand même très français ...) ...
Sinon, pour ton problème, puisque sNum contient un nombre et que dans ton string, tu veux récupérer le nombre sans son premier chiffre, il suffit d'utiliser l'instruction % (modulo) ...
Par exemple, si tu as sNum == 64, en faisant sNum = sNum % 10, tu auras alors sNum == 4, soit le dernier chiffre de sNum.
Reply With Quote
  #9  
Old 28-01-2004, 21:29
Samva's Avatar
Samva Samva is offline
Niaisüre within
 
Join Date: 24-04-2003
Location: Tours
Age: 39
Posts: 2,320
Send a message via ICQ to Samva Send a message via MSN to Samva
Re : delete the second character of a string?

C'est pas juste vous avez décidé de jouer sans moi, sinon batteur tu peux utiliser les fonctions atoi() de conversion de char* vers int, mais bon ... vu comme le topic est parti ca va etre fun
__________________
For the End-of-the-World spell, press "Ctrl, Alt, Delete."


Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
P2P : Majors, FAI, Etat, "main dans la main"... Toitoine Actualité 113 27-09-2004 19:28
W2K/XP "../ServicesPackFiles" Delete ? wuub Personnalisation de Windows 12 16-03-2003 08:31

All times are GMT +2. The time now is 20:21.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.