我正在制作一个个人程序,在其中,我得到一些字符串,可能有一个空格连字符空格.或类似的东西:" - "而我要做的就是用一个空格替换它.现在,问题是,当我尝试使用c#库中的替换方法时,它似乎没有做任何事情.这是我试过的:
string firsttext = firsttextbox.Text.ToLower();
string name = firsttext.Replace(" - ", " ");
Run Code Online (Sandbox Code Playgroud)
但是这无法用第一个文本的空格连字符空格模式替换单个空格中的字符串.因此,当我尝试使用此文本时,例如:
Code Geass - Lelouch of the Rebellion
Run Code Online (Sandbox Code Playgroud)
它只是将其返回到字符串名称:
Code Geass - Lelouch of the Rebellion
Run Code Online (Sandbox Code Playgroud)
但它应该实际上返回这个:
Code Geass Lelouch of the Rebellion
Run Code Online (Sandbox Code Playgroud)
我的想法怎么了?或者我可以采用不同的方式吗?我在这里先向您的帮助表示感谢.
请求的完整代码:http: //pastebin.com/hwUtFe8N
所以我正在开发一个Tic-Tac-Toe游戏,对于我的输入函数,我得到的是移动播放器作为一个整数存储在一个二维数组中,输入是通过引用指向位置的一维指针获得的在2D数组中.
但是我的问题是,当我似乎通过使用指针将多维数组的平方值设置为某个东西时,没有任何反应.
这是输入功能:
void Game::input(Board b){
int *spots[9]; // Possible spots for the input
bool validInput = false;
spots[0] = &b.board[2][0];
spots[1] = &b.board[2][1];
spots[2] = &b.board[2][2];
spots[3] = &b.board[1][0];
spots[4] = &b.board[1][1];
spots[5] = &b.board[1][2];
spots[6] = &b.board[0][0];
spots[7] = &b.board[0][1];
spots[8] = &b.board[0][2];
redo:
cout << ">> " << endl;
int input; // Input
cin >> input; // Get the input
validInput = cin;
if(!validInput){
cout << "Numbers only please!" << endl;
cin.clear();
while(cin.get() != '\n');
goto redo; …Run Code Online (Sandbox Code Playgroud) 什么是正确的写作方式:
<input type="hidden" name="recipient" value="<?php $user_id; ?>"/>
Run Code Online (Sandbox Code Playgroud)
我似乎无法获得提交值的表单.
我有以下代码,但是我不明白为什么以及它输出它的作用.
int main(){
int *i;
int *fun();
i=fun();
printf("%d\n",*i);
printf("%d\n",*i);
}
int *fun(){
int k=12;
return(&k);
}
Run Code Online (Sandbox Code Playgroud)
输出为12和垃圾值.有人可以解释输出吗?
它不应该两次都返回垃圾值吗?
我知道它k是本地的fun(),因此它将存储在堆栈中,并且当它fun()超出范围时它将被销毁.我在这里错过了什么概念?
我遇到的问题是为什么返回greatProduct和打印greatProduct输出不同的结果.前一个答案是错误的,后者是正确的.
#include <iostream>
#include <string>
using namespace std;
int largestproduct();
int main() {
cout << largestproduct() << endl;
}
int largestproduct()
{
const int adjacentDigits = 13;
int n = 0;
unsigned long greatestProduct = 0;
signed char num[] = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";
while(n <= 1000-adjacentDigits)
{
unsigned long product = 1;
for(int i = n; i < n+adjacentDigits;i++)
{
product *= (num[i] - '0');
}
if(greatestProduct < product)
{
greatestProduct = product;
}
n++;
}
cout << greatestProduct << endl; //the …Run Code Online (Sandbox Code Playgroud)