这是我的问题:我想检查用户是否通过检查他们是否只有字母(任何字母)和'或 - 在PHP中插入真实姓名和姓氏.我在这里找到了一个解决方案(但我不记得链接)如何检查一个字符串是否只有字母:
preg_match('/^[\p{L} ]+$/u',$name)
Run Code Online (Sandbox Code Playgroud)
但我也想承认'和 - 也是.(Charset是UTF8)有人可以帮我吗?
function binarySearch(value)
{
var startIndex = 0,
stopIndex = words.length - 1,
middle = Math.floor((stopIndex + startIndex) / 2);
while (words[middle] != value && startIndex < stopIndex) {
// adjust search area
if (value < words[middle]) {
stopIndex = middle - 1;
} else if (value > words[middle]) {
startIndex = middle + 1;
}
// recalculate middle
middle = Math.floor((stopIndex + startIndex) / 2);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在以数组格式制作大量单词:
例如 ["a","ab","abc","b"]
按字母顺序。我遇到的问题是修改我的二进制搜索算法以在正确的位置添加单词然后更新?
将单词添加到有序数组中的最佳性能方法是什么?为什么它是最好的方法?
我正在使用此方法将数据存储在数据库中:
$content = $_POST['content'];
$content = mysqli_real_escape_string($mysqli,$content);
$stmt = $mysqli->prepare("INSERT INTO na_posts(postuid,content) VALUES (?, ?)");
$stmt->bind_param("ss",$post_id,$content);
$stmt->execute();
$stmt->close();
Run Code Online (Sandbox Code Playgroud)
我使用此代码从数据库中获取数据:
$sql = "SELECT * FROM na_posts WHERE postuid = '" . $id . "'";
$stmt = $mysqli->query($sql);
$row = $stmt->fetch_Object();
echo nl2br($row->content);
Run Code Online (Sandbox Code Playgroud)
但输出是这样的:
嘿这是第一行\ r \n这是第二行
为什么新线条会像这样出现\r\n?
如果我删除了对mysqli_real_escape_string()我看过的安全性很重要的调用,它就可以工作.
我有以下复杂的,不是结构良好的XML:
<event hometeam="K.Kanepi" awayteam="S.Lisicki" eventName="K.Kanepi-S.Lisicki" date="02/07/2013" time="14:05" datetime="2013-07-02T14:05:00+02:00">
<subevent title="Match odds" dsymbol="MATCH_ODDS">
<selection name="home" odds="3.1500" slipURL="URI/en/add-bet/3187-02072013,1"/>
<selection name="away" odds="1.3500" slipURL="URI/en/add-bet/3187-02072013,2"/>
</subevent>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下代码解析它:
$total_games = $xml->event->count();
for ($i = 0; $i < $total_games; $i++) {
echo $xml->event[$i]->subevent.title;
Run Code Online (Sandbox Code Playgroud)
$ total游戏正常运行; 然而 - 当我尝试解析子事件时,我没有成功获取eventName,hometeam,date等.
我有一个程序,我创建了两个线程.在一个线程中,我为整数a和b分配了一个值.在第二个线程中,我想访问a和b,以更改其值.
#include <stdio.h>
#include <pthread.h>
struct data {
int a;
int b;
};
struct data temp;
void *assign(void *temp)
{
struct data *new;
new = (struct data *) temp;
new->a = 2;
new->b = 2;
printf("You are now in thread1..\n The value of a and b is: %d, %d", new->a + 1, new->b + 1);
printf("\n");
pthread_exit(NULL);
}
void *add(void *temp1)
{
struct data *new1;
new1 = (struct data *) temp1;
printf("You are now in thread 2\nValue of a and …Run Code Online (Sandbox Code Playgroud) 我正在尝试从文件中读取这个json数据
[{"name":"Luke","score":50},{"name":"Ryan","score":70}]
Run Code Online (Sandbox Code Playgroud)
码:
JsonParser parser = new JsonParser();
try{
Object obj = parser.parse(new FileReader("C:/Users/user/Documents/HighscoresJSON.json"));
JSONObject jsonObject = (JSONObject) obj;
String usersName = (String) jsonObject.get("name");
System.out.println("Name of user: " + usersName);
int usersScore = (int) jsonObject.get("score");
System.out.println("Score: " + usersScore);
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
com.google.gson.JsonArray cannot be cast to org.json.JSONObject
#include <stdio.h>
#include <string.h>
int main(void)
{
char str1[1000];
int i, letter, space = 0;
char ch = str1[i];
printf("Enter a sentence: ");
scanf("%[^\n]s", str1);
printf("you enter %s\n", str1);
while (i != strlen(str1)) {
if (ch != ' ') {
letter++;
} else if (ch = ' ') {
space++;
}
i++;
}
printf("%d %d", letter, space);
}
Run Code Online (Sandbox Code Playgroud)
我的while循环不起作用,我似乎无法找到问题.我在ubuntu中使用终端,在打印用户字符串后,我得到一个空行.我必须使用Ctrl-Z来停止脚本.
我试图理解Java中的枚举,但目前找不到解释我问的问题的帖子.
我有一个Person界面和一个PersonEO类.Person接口的两种方法是setGender和getGender.我想把性别作为一个枚举.
我是否在界面中创建枚举并将其转移到课程中,或者在课堂上创建枚举?
这是我一直在尝试的但是无法让enum正确地传递给类,并且不能真正理解它将如何流经程序.
public interface Person{
public enum gender{
Female,
Male,
Unknown;
private String gender;
public String getGender(){
}
void setGender(){
}
}
------------------------------------------------------
public class PersonEO implements Person {
//Both override methods are not seen as methods from the interface
@Override
public String getGender() {
return gender;
}
@Override
public void setGender() {
//Not sure how to set the gender from the enum
this.gender = gender;
}
}
Run Code Online (Sandbox Code Playgroud)
请举例说明.
我有两个功能.一个函数调用打印功能.
调用函数(key是一个介于0和42之间的数字,表示遥控器的键,keymap只是将名称映射到键):
void calling_function(int key){
print_info("[KEY]", ("%#4x %s", key, keymap[key - 1]));
...
}
Run Code Online (Sandbox Code Playgroud)
和打印功能:
print_info(char *prefix, char *message){
print("%s %s\n", prefix, message);
}
Run Code Online (Sandbox Code Playgroud)
但输出看起来像这样:
[KEY] COLOR_RED
所以缺少int,为什么不插入整数?我想不合作sprintf()
map不使用TSLint的情况下使用遍历数组并返回新对象:可以通过省略花括号和关键字“ return”,并将对象文字括在括号中来简化此箭头函数的主体。
例如,对象用户:
class User {
constructor(
public id: number,
public first_name: string,
public last_name: string,
public gender: Date,
public location: number,
)
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时:
const simple_users = users.map(u => { return { name: u.name, id: u.id} });
Run Code Online (Sandbox Code Playgroud)
然后发生这种情况:
[tslint]通过省略花括号和 关键字“ return”,并将对象文字括在括号中。(箭头返回简写)
而且我要遵守tslint规则arrow-return-shorthand。