问题列表 - 第38601页

从PHP数组中删除字符串?

是否可以在不知道索引的情况下从PHP数组中删除字符串(参见下面的示例)?

例:

array = array("string1", "string2", "string3", "string4", "string5");
Run Code Online (Sandbox Code Playgroud)

我需要删除string3.

php arrays string

17
推荐指数
3
解决办法
3万
查看次数

C编程sqrt函数

#include <math.h> 
#include <stdio.h> 

int main(void) 
{ 
    double x = 4.0, result; 

    result = sqrt(x); 
    printf("The square root of %lf is %lfn", x, result); 
    return 0; 
} 
Run Code Online (Sandbox Code Playgroud)

此代码不起作用,因为它采用变量的平方根.如果你改变了sqrt(x),to sqrt(20.0),代码工作正常,为什么?请解释.

另外,我如何获得变量的平方根(这是我真正需要的)?

OUTPUT:

matthewmpp@annrogers:~/Programming/C.progs/Personal$ vim sqroot1.c
matthewmpp@annrogers:~/Programming/C.progs/Personal$ cc -c sqroot1.c
matthewmpp@annrogers:~/Programming/C.progs/Personal$ cc -o sqroot1 sqroot1.c
matthewmpp@annrogers:~/Programming/C.progs/Personal$ ./sqroot1
4.472136
matthewmpp@annrogers:~/Programming/C.progs/Personal$ vim sqroot2.c
matthewmpp@annrogers:~/Programming/C.progs/Personal$ cc -c sqroot2.c
matthewmpp@annrogers:~/Programming/C.progs/Personal$ cc -o sqroot2 sqroot2.c
/tmp/ccw2dVdc.o: In function `main':
sqroot2.c:(.text+0x29): undefined reference to `sqrt'
collect2: ld returned 1 exit status
matthewmpp@annrogers:~/Programming/C.progs/Personal$ 
Run Code Online (Sandbox Code Playgroud)

注意:sqroot1是20.0的sqroot.sqroot2是变量的sqroot.

matthewmpp@annrogers:~/Programming/C.progs/Personal$ cc …
Run Code Online (Sandbox Code Playgroud)

c

6
推荐指数
1
解决办法
5万
查看次数

正则表达式从字符串中删除任何货币符号?

我正在尝试从字符串值中删除任何货币符号.

using System;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string pattern = @"(\p{Sc})?";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            decimal x = 60.00M;
            txtPrice.Text = x.ToString("c");
        }

        private void btnPrice_Click(object sender, EventArgs e)
        {
            Regex rgx = new Regex(pattern);
            string x = rgx.Replace(txtPrice.Text, "");
            txtPrice.Text = x;
        }
    }
}
// The example displays the following output:
// txtPrice.Text = "60.00";
Run Code Online (Sandbox Code Playgroud)

这有效,但不会删除阿拉伯语中的货币符号.我不知道为什么.

以下是带有货币符号的示例阿拉伯字符串.

txtPrice.Text = "?.?.? …
Run Code Online (Sandbox Code Playgroud)

c# regex

5
推荐指数
1
解决办法
6204
查看次数

点击'X'元素时触发UISearchBar和事件

在UISearchBar上,有一个X元素允许您一次清除所有内容.有没有办法在发生这种情况时收到通知?

UISearchBarDelegate::searchBarCancelButtonClicked 仅在点击"取消"按钮时触发.

iphone uisearchbar uisearchbardelegate

9
推荐指数
1
解决办法
2万
查看次数

在Java中检查二维数组中的邻居的更有效方法

嘿所有,对于我的一些大学作业,我发现需要检查二维阵列(网格)中的相邻单元格.我使用的解决方案是使用异常的一些黑客攻击,我正在寻找一种方法来清理它,而不需要if像我的一些同学一样的大量语句.我目前的解决方案是

for ( int row = 0; row < grid.length; row++ ) {
    for ( int col = 0; col < grid.length; col++ ) {
        // this section will usually be in a function
        // checks neighbours of the current "cell"
        try {
            for ( int rowMod = -1; rowMod <= 1; rowMod++ ) {
                for ( int colMod = -1; colMod <= 1; colMod++ ) {
                    if ( someVar == grid[row+rowMod][col+colMod] ) {
                        // do something
                    } …
Run Code Online (Sandbox Code Playgroud)

java performance exception multidimensional-array

8
推荐指数
3
解决办法
4万
查看次数

创建DiskFileItem时出现java.lang.NullPointerException

我正在尝试使用Spring 3编写一个单元测试来处理文件上传控制器.现在,如果我通过控制器将图像发送到我的服务方法,一切正常.但是在进行直接单元测试时,我得到一个空指针异常.

DiskFilteItem当我手动实例化它时,它内部的属性"dfos"似乎是null,但是当MultipartFile从控制器检索a时它被填充.

    File file = new File("//Users//test//Downloads//testimage.jpg");
    log.info("found file: " +file.exists());
    log.info("file size: " +file.length());
    String fieldName = "field";
    String contentType = "image/jpeg";
    boolean isFormField = false;
    String fileName = "testimage.jpg";
    int sizeThreshold = 10240;

    DiskFileItemFactory factory = new DiskFileItemFactory();

    DiskFileItemFactory factory = new DiskFileItemFactory();
    // throws null pointer
    FileItem fi = factory.createItem(fieldName,contentType,isFormField,fileName);

    // so does this one
    DiskFileItem item = new DiskFileItem(fieldName, contentType, isFormField, fileName, sizeThreshold, file);
    MultipartFile f = new CommonsMultipartFile(item);
Run Code Online (Sandbox Code Playgroud)

我觉得我在设置中遗漏了一些愚蠢的东西.我的pom文件包含以下依赖项.

    <dependency>
        <groupId>commons-fileupload</groupId> …
Run Code Online (Sandbox Code Playgroud)

java spring file-upload apache-commons-fileupload

4
推荐指数
1
解决办法
7164
查看次数

char和char之间的区别[1]

在C++中,使用char和char [1]之间有什么区别(如果有的话).

例子:

struct SomeStruct
{
   char x;
   char y[1];
};
Run Code Online (Sandbox Code Playgroud)

对于unsigned char,原因如下吗?

c++ arrays char static-array

55
推荐指数
2
解决办法
8568
查看次数

如何测试一个矩形是否在另一个矩形中?

好吧,所以我正在开发一款游戏,我发现我的敌人不喜欢我的碰撞检测,这对我的玩家来说非常有效.经过一些调试我发现它是因为我的敌人比我的瓷砖大,而我的玩家比我的瓷砖小.

现在我需要能够成为大敌和老板,所以这不会做.所以我需要找出一种更好的方法来测试碰撞检测.这就是我目前的做法:

上和下:

if((enemy.left > tile.left && enemy.left < tile.right || enemy.right > tile.left && enemy.right < tile.right) && enemy.top < tile.bottom && enemy.bottom > tile.top){
    //collision
}
Run Code Online (Sandbox Code Playgroud)

左和右:

if((enemy.top > tile.top && enemy.top < tile.bottom || enemy.bottom > tile.top && enemy.bottom < tile.bottom) && enemy.left < tile.right && enemy.right > tile.left){
     //colision
}
Run Code Online (Sandbox Code Playgroud)

c# c++ java collision-detection

3
推荐指数
1
解决办法
582
查看次数

为什么要用'自我'.什么时候不被迫?

我注意到我编码的方式(严重;))与我从其他人看到的代码之间存在差异.

谁能解释为什么我看到有些人在使用

self.varname.anotherpropertie
Run Code Online (Sandbox Code Playgroud)

什么时候

varname.anotherpropertie
Run Code Online (Sandbox Code Playgroud)

似乎工作也一样.我不用自己.在我的代码中很多.我想知道这是非常糟糕的还是我需要学习的东西才能理解为什么它被大多数人使用了这么多?

再次感谢,-Code

iphone objective-c

0
推荐指数
1
解决办法
197
查看次数

表单上的多个按钮

我有一个清晰的按钮,我想绑定到一些PHP编码.如何检测是否按下了清除按钮.当用户按清除时,我将更新sql表以清除条目.但首先我需要知道按下按钮的时间.

<input name="Reset1" type="reset" value="clear" />
Run Code Online (Sandbox Code Playgroud)

html php

8
推荐指数
1
解决办法
4万
查看次数