C++ :: Remove Char From String?

Aug 9, 2013

I've to do a function that removes char(input by user) from string , only if it appeared and to reduce spaces.

for instance: string = abcabcd ; and the char= c/
the return string is : ababd

void removeChar(char string2[SIZE], char ch) {
//---NOTE--- its not completely works - there is a problem i.
int read = 0, write = 0;

[Code].....

View 6 Replies


ADVERTISEMENT

C++ :: Remove Char Without Space From String

Aug 6, 2013

I need to remove a char from string that found ;

For example : string- abcdfe
the char ch is - c
and the return new string is : abdfe.

I did as follow:

void removeChar(char string2[SIZE], char ch) {
char input= 'a'; // for example replace something
int i=0;

if(string2[i]== ch && string2[i]!='/0') {
string2[i]= input;
}
i++;
}

and in the main : I only called to this function above and print string.

View 4 Replies View Related

C Sharp :: Remove Specific Char In String

Jul 5, 2013

int index = -1;
string NewStr = null;
char[] lower = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char[] upper = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};  
foreach (char c in str)

[Code]....

The code above loops through a string and for each character checks to see if it is a lower case character, then checks to see if it an upper case. It then removes it if it is. Leaving only the numbers.

However, it reuses the same string the entire time, never updating the string so it always finds the same (first) character.

View 6 Replies View Related

C/C++ :: How To Remove And Replace Some Char In A File

Jun 3, 2014

I want to remove some character in my file. too i want to replace some char to another. I know the easiest way for this job is we write final text in file. i mean we first produce sightly text then write it in file . I don't want use of temporary string.

View 3 Replies View Related

C :: Remove Duplicate Strings From Char Array

Apr 15, 2014

The goal is to merge two files of names, sort them and remove duplicates.I've managed to merge the two files into a single char array and sort them with a function so they are alphabetical.I'm having problems removing the duplicate entries from the array. Here is my code:

Code:

#include <stdio.h>
#include <string.h>
#define NUMSTR 10
#define STRLNG 9

[Code]....

View 3 Replies View Related

C :: Remove Spaces From String

Mar 19, 2013

I'm unable to print out or return the inputted string modified.

Code:

//ch11_9.c
//remove_spaces(char* given_string)
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
char* remove_spaces(char *given_string){

[Code]...

View 12 Replies View Related

C/C++ :: Remove Character In String?

Mar 1, 2014

I need to make a function that removes a function in a c-string. This is what I have:

#include <iostream>
using namespace std;
char removeCharacter (char *str, char c)
{

[Code].....

View 5 Replies View Related

C# :: Remove Folder Name In A String?

Jul 14, 2014

I want to remove the folder name in a string example C:/test/desktop/new folder/test.xls.i want the string "test"alone and folder may vary.

View 3 Replies View Related

C Sharp :: How To See If String Contains Two K And Remove Last One

Oct 11, 2012

I am writing a parse system, and I want to go in and check a string for multiple Ks to be exact a K at the beginning and one at the end, if it does have a K at the end of the string I want to remove that K. I don't have an exact size of my string. I know how to remove the last K but not how to check the string for the multiple Ks.

This is what I have:

            if (poNumber.Contains("K...K"))
                poNumber.Remove(poNumber.Length - 1,1);

I know that the first part will not work the way I want it to.

View 6 Replies View Related

C :: WAP To Remove Vowel String Using Pointer And Function

Jan 25, 2013

WAP to remove vowel string using Pointer and Function...

View 6 Replies View Related

C/C++ :: Remove Vowels From User Input String

Aug 13, 2013

how to remove the vowels from the user input.?

View 4 Replies View Related

C++ :: Count String In A String Using Datatype Char

Dec 20, 2014

I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:

Code:

#include <iostream>
#include <conio.h>
using namespace std;
int main ()

[Code] ....

View 6 Replies View Related

C++ :: Char Array To String - String Becomes Garbage

Apr 20, 2013

I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.

// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);

[Code] ....

View 3 Replies View Related

C++ :: String Class That Finds A Char In String?

Feb 5, 2013

A string class that finds a char in the string?

View 1 Replies View Related

C++ :: Getting A Char From A String

Apr 5, 2013

I have this problem that I don't know how to sort out. I have a feeling it's really simple

#include <iostream>
#include <string>
void main () {
char test[10] = "gorilla";
char try = test[1];
cout << try;
}

I get the error:
lab4.cpp:6: error: expected primary-expression before "char"
lab4.cpp:6: error: expected `;' before "char""

View 2 Replies View Related

C :: How To Get ASCII Value Of A Char In A String

Mar 4, 2013

how can I find ASCII value (0..255) of a character char in a string?

I have an array of char:

Code: char myarray[50]; and I need to have ASCII value of character eg myarray[10]. How can I do that?

View 1 Replies View Related

C++ :: Char Array To String

Oct 19, 2013

I have some code:

char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);

After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".

Then, I use

std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);

szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.

Or is there something I'm missing? Maybe the termination character, or something.

View 1 Replies View Related

C++ :: Convert String To Char

Apr 30, 2013

Is there anyway to convert std::string to char*?

Like:

std::string x="hello world";
char* y=x;

View 6 Replies View Related

C++ :: How To Transform A String Into A Char

Feb 8, 2015

I have had quite a head spinner on trying to transform a string into a char. I've been trying to do this for the project below.

[URL] ....

std::string str = "string";
const char* chr = str.c_str();
cout << *chr << endl;

Above is the code I have tried using and it stores data under *chr, it however only stores one letter rather than the entire word like for example string.

View 2 Replies View Related

C++ :: Convert String Of Hex To Char

Jul 5, 2013

I have this code working:

char tmp_wku[3];
tmp_wku[0]=0x01;
tmp_wku[1]=0x9D;
tmp_wku[2]=0x62;
char tmp_com[11];

[Code] ....

This sends the buffer to a LIN modem. My question is: can this be done better. If I have a astring of hex numbers like "09 98 88 55 42 FF 00 00 FF BD 89". How could I send this without manually makng a char with hex numbers?

View 1 Replies View Related

C++ :: Replace Char In String

May 7, 2013

Is there a way to replace 3 char's in a string. For example i have a string containing

s = "The school is called 7x8"

I want to replace the "7x8" with "LSU". But the "x" can be any letter or number.

Is there a way to do that ?

View 6 Replies View Related

C++ :: Conversion Between Char And String

Jun 7, 2013

I have a question on conversion between char & string. I have cut & pasted the part of the code from my C++ code and my function "decryptPwd" uses C style code with "char" etc.

I need to pass a string (mypwd) somehow to this function after conversion & then compare it to another string (newmypwd).

I tried - "decryptPwd(mypwd.c_str())==newmypwd.c_str()" but it did not work.

..
#include <string>
..
char* decryptPwd(char hash[64]);
main () {
string mypwd;
string newmypwd;
if (decryptPwd(mypwd)==newmypwd)

[Code] ...

View 7 Replies View Related

C/C++ :: Appending Char To String

Dec 1, 2013

#include <stdio.h>
#include <stdlib.h>
#include <string.h>  
int main() {
    char states [6][10]={"start","InNum","InID","Done","InASG","InCOM"};
    char state[] = "start";

[Code] .....

I am trying to take each character from a file and put it in a string and print this string but when i write this code , it doesn't give any output.

View 6 Replies View Related

C++ :: Binary Char Pointer Into String

Jun 12, 2013

Is there a more simple method to copy Buf into str? Buf is a binary string.

Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}

View 5 Replies View Related

C++ :: Converting String To Char Array

Mar 30, 2014

In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.

ReadNew function reads the file....check to see if it exist

CreateNew function creates a new file.

In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.

Code:

//Create a file, append to it, and read it.
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);

[Code]...

View 1 Replies View Related

C :: Printing A Char String From A Struct

Jan 3, 2015

I am trying to save 5 persons names to a struct, and then printing them afterwards, shortly before the program ends. I tried to print the char string out right after it has been copied over, and it showed fine, but when i try to write it out right at the end of the program (its in a separate function) the terminal just prints gibberish.

the function looks like this:

Code:
int printUser(){
printf("Following patients have been recorded in this session:
");
struct database patient1;
struct database patient2;
struct database patient3;

[Code]...

the output looks like this(as you can se in under structest, that it shows the correct string, it also uses printf):

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved