小编duk*_*vin的帖子

Java:system.out.println 连接字符串中的某些内容(非常简单的问题)

我希望我的输出是 Candy[1]。计数器整数 = 1

但我的编译器不接受这段代码:

   System.out.println("Candy["+counterInt"]");
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能让这个变量出现在字符串 Candy[] 中?

Candy[] 不是一个数组,而是一个字符串。

java syntax println

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

PHP:比较子串

用PHP真的很快的noob问题:

我正在尝试创建一个条件语句,我可以检查变量是否与子字符串部分匹配.

在我的案例中更具体:

$ cal是文件的名称,我想要它,所以如果$ cal包含".cfg",它会回显一些文本.

伪代码:

<?php if ($cal == "*.cfg")
 {
    echo "Hello ";
 }
?> 
Run Code Online (Sandbox Code Playgroud)

php string compare

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

PHP:从字符串中提取名称

我有一条看起来像这样的路径:

/home/duke/aa/servers/**servername**/var/...morefiles...

使用php,我想从路径中提取"servername"

不幸的是我不是那么精通php,但我想出了一些使用strstr()但我只使用PHP版本5.2的地方,其中一个参数函数需要5.3

什么可能会返回"servername"的代码?

php string strstr

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

PHP:替换所有实例

我有一个看起来像这样的chatlog文件(名称代表屏幕名称,文字是他们的聊天字符串)

name: some text
name2: more text
name: text
name3: text
Run Code Online (Sandbox Code Playgroud)

我想把所有名字都染成:红色.
例如:<font color=red>myname:</fontcolor> hello 我该怎么做?

我不知道为什么,但这段代码在冒号之后对所有内容进行着色

echo preg_replace('/(.*?):/', "<font color=#F00>$1</font>:", $output);
Run Code Online (Sandbox Code Playgroud)

php regex replace preg-replace

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

特殊字符显示为?分数

我在这里有一些特殊字符:http:
//209.141.56.244/test/char.php

但是当我在这里通过ajax获取此文件时,它们会显示为返回?标记:http :
//209.141.56.244/test/char.html

这些字符应为"ISO-8859-1 Western",但将我的浏览器编码切换为任何选项都无济于事.

为什么这样,我该如何解决?

html php unicode ajax encoding

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

Java:添加到数组列表

public class Maze
{
    public static final int ACTIVE = 0;
    public static final int EXPLORER_WIN = 1;
    public static final int MONSTER_WIN = 2;
    private Square[][] maze;
    private ArrayList<RandomOccupant> randOccupants;
    private Explorer explorer;
    private int rows;
    private int cols;

public Maze(Square[][] maze, int rows, int cols, int numTreasures, int numMonsters, String name)
{   
    int i;
    this.maze = maze;
    this.cols = cols;
    this.rows = rows;

    randOccupants = new ArrayList<RandomOccupant>();

  for (i = 0; i < numTreasures; i++) 
  {
    randOccupants.add(i) = …
Run Code Online (Sandbox Code Playgroud)

java syntax arraylist

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

C++这个简单的类有什么问题?

刚学习C++中的Classes,我认为我对它的掌握相当不错,但由于某种原因,这段代码甚至无法编译.

#include <iostream>
#include <cstdlib>

using namespace std;

class Position
{
    int row;
    int column;
public:
    Position();         //constructor
    ~Position();        //destructor
    void setPos(int, int);  //set the position
    int getRow();       //return the current row
    int getColumn();    //return the current column
    void getPos();      //print the pos
    bool compare(int, int); //compare a row and column with the one in the class
};

Position::Position()
{}
Position::~Position()
{}
void Position::setPos(int x, int y)
{
    Position.row = x;
    Position.column = y;
}
int Position::getRow()
{
    return Position.row; …
Run Code Online (Sandbox Code Playgroud)

c++ class

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

PHP:知道是否设置了来自explode的值

http://codepad.org/GAl6W6xn

为什么这段代码说"未设置"?什么是数组位置2设置为使其说"设置"?我如何处理这个问题,以便知道位置2中是否存在值?

(抱歉缺少一个好头衔,想不到一个)

php explode

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

*-transform:rotate在Firefox中工作但不在chrome中工作

CSS看起来如下:

.rotate
{
    -webkit-transition: all .5s ease-in-out; 
    -moz-transition: all .5s ease-in-out; 
    -o-transition: all .5s ease-in-out; 
    -ms-transition: all .5s ease-in-out;
}
.rotate:hover
{
    -webkit-transform: rotate(90deg) scale(1); 
    -moz-transform: rotate(90deg) scale(1); 
    -o-transform: rotate(90deg) scale(1); 
    -ms-transform: rotate(90deg) scale(1); 
}
Run Code Online (Sandbox Code Playgroud)

将鼠标悬停在一个<span class="rotate">将在Firefox中旋转元素但不旋转铬.
演示:http://jsfiddle.net/BuHGQ/(将鼠标悬停在箭头上方)

可以做些什么才能在Chrome中运行?

css cross-browser css3

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

PHP返回数组键

我有一个数组美食像:

Array
(
    [apple] => Array
        (
            [color] => red
            [type] => fruit
        )

    [choco] => Array
        (
            [color] => brown
            [type] => candy
        )

)
Run Code Online (Sandbox Code Playgroud)

有功能我可以做:

get_key($ food,0)它将返回索引0,apple

get_key($ food,1)返回choco

php multidimensional-array

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