It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am getting a value like this
"RE000022000500200Ì 0.00 0.1 0.129.8#####- 97- 2#####- 1##### 960.504.00 0: 00.000.00 8: 013:52 0: 021:52############2.00.0 "
I want a value like this after doing some processing on above data can you You please what should be the logic to remove "Ì"
"RE000022000500200 0.00 0.1 0.129.8#####- 97- 2#####- 1##### 960.504.00 0: 00.000.00 8: 013:52 0: 021:52############2.00.0 "
If there's no character that's value is 0xC3 in your data, you can traverse your data string, if an character that it's value equals 0xC3 occur, then remove the character and the next character.
It's easy enough if you are using std::string to hold your value.
#include <string>
#include <algorithm>
std::string input = ...;
input.erase(std::remove(input.begin(), input.end(), 'Ì'), input.end());
It's more complex if you insist on using C strings or arrays.
I see from the comments above that you are using C strings. I suggest you switch to using C++ strings.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I need to convert the string "Test €" to "Test € ;" and vice versa. Please make a note that its a string and not from the xml. For your information I am developing the application in C++ and using Xerces also for XML Parsing. Please help me how it can be achieved in c++ application.
Thanks,
Ram
I think this answer may be platform-dependent, though I don't know for sure.
You can use stringstreams and casting. If lookup is a string holding the decimal version of the character code, this function will return the character version:
char fixchar(string lookup){
stringstream converter (lookup);
int i;
converter >> dec >> i;
return (char)i
(Note that for hex strings, which are prefixed with #x instead of #, you can just use hex instead of dec).
You can get the lookup strings by using the find function on the original string. Here's a loop that uses the above function to convert a string (called fixd) with &#x[number] substrings into a normal string with no character codes:
while (fixd.find("&#x")!=string::npos){
tag = int(fixd.find("&#"));
endtag = int(fixd.find(";"));
fixd = fixd.substr(0,tag) + fixchar(fixd.substr(tag+3,endtag-tag-3)) + fixd.substr(endtag+1, fixd.length()-tag-4);
}
Similarly, you should be able to get the int version of a character just by casting it, after which you can do whatever you want with it, including adding it in decimal form to a string.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I found following C++ source code:
void victory()
{
printf("xxxxxxxxxxxxxxxxxxxxxxxx"); //random string
}
int main()
{
if(0) victory();
/* code here! */
}
Your main objective is to print the random string(from function victory) on stdout
How can It possible? How can I print the random string? It's a tricky traps, just for curiosity. Above all, I can't use pointers...
Rules:
Max 12 chars.
You can't use: "main", "victory", "asm", "%", "*", "_", "#", "/", "&".
You have only one semicolon.
It is pretty clear that there is no way to solve this in any remotely standards-compliant way.
Since this is being framed as a "security" question, this suggest that it's OK to use compiler- and OS-specific hacks. With this in mind, the following works on my system using gcc:
#include <stdio.h>
void victory()
{
printf("SxxxxxxxxxxxxxxxxxxxxxxE"); //random string
}
int main()
{
if(0) victory();
puts(""-25);
}
It relies on the fact that the "" gets placed by the compiler immediately after the string literal that we're trying to recover. Here, 25 is the (known) length of the unknown string.
Of course, this has UNDEFINED BEHAVIOUR written all over it in huge neon letters. Handle with care.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an array of strings and an array of ints. Usually when I want to get a certain char from string I use:
string[char_position];
But when I have two arrays the same way of getting char doesn't work:
string[i][char_position[i]];
How can I get certain char from array of strings?
Try it like this instead:
string[i][char_position];
You sholdn't be subscripting char_position.
In first example you are using char_position as int but in second you are using it as array. Either one of this is wrong obviously if you mean same variable in two cases. But what it looks like you want to access jth charecter of ith string. If it is that then
string[i][j]; // j is position of char in string[i]
string[i][char_position[i]]; means the instructions:
get the INTEGER from char_position array indexed at i
get the character in ith string, in the position got from the first step
This is valid and correct ONLY if char_position is an ARRAY and not a SCALAR VARIABLE.
On the other hand, if char_position IS a scalar variable THEN:
string[i][char_position] is the way to retrieve char_positionth character in the ith string, in the array of character arrays string
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am wrting a c++ function to implement string replacement. The function is like:
using namespace std;
string Replace(const string & str, const string & strOld,
const string & strNew, bool useRegex, bool caseSensitive)
{
regex::flag_type flag=regex::basic;
if(!caseSensitive)
flag |= regex::icase;
if(!useRegex)
// WHAT TO DO ?
std::regex rx(strOld,flag);
string output=regex_replace(str,rx,strNew);
return output;
}
It replaces all occurrences of strOld in str to strNew. I attempted to use std::regex and std::regex_replace to implement it. It works well in case useRegex is true. However, in case useRegex is false, I am not able to tell them that strOld is just a plain string instead of a regex string.
For example, When I call:
string output=Replace("hello.",".","?",false,true);
It returns "??????" while I expect it to be "hello?".
Halfway-solution is to pre-process the regex and escape all metacharacters manually. It's the best solution if this feature is missing from C++11 which from comments sounds like it is.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Is it not possible to fill a map like this:
void Spel::Fill( void )
{
int buildslist[] = {3,3,2,2,2,2,3,2,2,2,2,3,3,2,2,2,2,1,1,1,1,1};
Building::buildings p;
for( int i = Building::INDIGOK; i < Building::STADSHUIS; i++)
{
p = (Building::buildings) i;
gebouwenMap[p] = buildslist[i];
}
}
This gives all 0. Building::buildings is an enum with some building names. The buildslist is a list of how many people could join that building.
First, there is not enough code to give an actual answer. Please improve your question so that we can help you properly.
Second, the title is misleading "Find function doesn't return the right value". There is no "find" function and there is no "return value" because the only function you show returns void.
Now thet this is sorted out, let me try to help you:
p = (Building::buildings) i;
This is a cast from int to enum. I think this is bad C++ (probably undefined as in might work for some compiler but not as a rule of thumb). You would have to use a switch here I think.
Please write code in English. Do you imagine if someone you work with is Japanese and would write the code with japanese variable names? Even if the project is in Dutch, write code in English including comments.
EDIT: You might want to use strings instead of an enum here.
Try using a std::map<std::string, int> to encode your building names instead of an enum, then use an std::map::iterator to iterate through it.