我想做这样的事情
def get_count(string)
sentence.split(' ').count
end
Run Code Online (Sandbox Code Playgroud)
我认为可能有更好的方法,字符串可能有内置方法来做到这一点。
出于测试和学习目的,是否有一个控制台可用于发送 http 请求,例如
\n\n\nGET /index.html HTTP/1.1\xe2\x90\x8d\xe2\x90\x8a\n 主机:www.example.com\xe2\x90\x8d\xe2\x90\x8a\n \xe2\x90\x8d \xe2\x90\x8a\n\n\n
并得到回应。
\n\n我知道curl 非常方便,但我要探索的是底层的内容
\n\n或者将请求写入文本文件并通过curl 发送?
\n通过以下方式将服务器响应发送到客户端很方便
server = TCPServer.open 1234
socket = server.accept
socket.puts 'data from server side'
Run Code Online (Sandbox Code Playgroud)
在客户端,在这种情况下卷曲
curl -v localhost:1234
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 1234 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:1234
> Accept: */*
>
data from server side
Run Code Online (Sandbox Code Playgroud)
在这一点上,似乎我仍然可以在 curl 中输入一些东西,所以我假设 tcp 连接是双向的,我输入
data from the curl client
Run Code Online (Sandbox Code Playgroud)
之后,如何从当前 TCPSocket 实例中的 curl 客户端接收此消息?
我试过了
socket.read
Run Code Online (Sandbox Code Playgroud)
但它不起作用
在ruby中,因为它在系统范围内编码为utf-8.所以它很直接:
string ="\ u7f51\u5740\u4e0d\u80fd\u4e3a\u7a7a"
=>网址不能为空
任何人都可以告诉我如何在vim中这样做?
我想创建一个字符串数组.这是代码:
#include <stdio.h>
int main(void){
char str1[] = {'f','i'};
char str2[] = {'s','e'};
char str3[] = {'t','h'};
char arry_of_string[] = {str1,str2,str3};
printf("%s\n",arry_of_string[1]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是不起作用的行:
char arry_of_string[] = {str1,str2,str3};
Run Code Online (Sandbox Code Playgroud)
我该如何纠正?
从这里的现有问题,有人给出了这个示例代码:
int status;
child_pid = fork();
if (child_pid == 0) {
// in child; do stuff including perhaps exec
} else if (child_pid == -1) {
// failed to fork
} else {
if (waitpid(child_pid, &status, 0) == child_pid) {
// child exited or interrupted; now you can do something with status
} else {
// error etc
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以向我解释第二个参数waitpid()用于什么?
我正在做一个项目,经常需要此功能
'b' + 1 #=> 'a' and 'b' - 1 #=> 'a'
Run Code Online (Sandbox Code Playgroud)
现在我的解决方案非常繁琐:
str(unichr((ord('b')+ 1)))
Run Code Online (Sandbox Code Playgroud)
有没有更优雅的方法可以做到这一点?
def sum10(a, b):
if sum([a, b]) % 10 == 0: return True; return False
print sum10(7, 3)
print sum10(-13, -17)
print sum10(3, 8)
Run Code Online (Sandbox Code Playgroud)
结果是:
True
True
None
Run Code Online (Sandbox Code Playgroud)
不是我的预期:
True
True
False
Run Code Online (Sandbox Code Playgroud)
任何的想法?
<?xml version="1.0" encoding="utf-8"?>
<items>
<item>
<title>This is title1</title>
<desc>This is desc1</desc>
<image></image>
<tudou></tudou>
</item>
<item>
<title>This is title2</title>
<desc>This is desc2</desc>
<tudou>55362137</tudou>
</item>
<item>
<title>This is title3</title>
<desc>This is desc4</desc>
</item>
</items>
Run Code Online (Sandbox Code Playgroud)
这是我的PHP代码:
<div class="nav">
<ul>
<?php
$xml = simplexml_load_file('post.xml');
//print_r($xml);
foreach($xml->item as $key=>$item )
{
echo <<<HTML
<li>
<div class="published">
<span class="day">13</span>
Sep 2010
</div>
<div class="summary">
<a href="#slide-$key">
<h3>$item->title</h3>
</a>
</div>
</li>
HTML;
}
?>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
在php渲染页面后,<a href="#slide-$key">返回<a href=#slide-item>.我想要$ key获取其中的数量,那么如何获得?