我需要删除String的一些部分,一些字符串示例:
$string1 = 'Castanho / Brown';
$string2 = 'Cor de Rosa / Pink';
Run Code Online (Sandbox Code Playgroud)
我需要在"/"之后删除字符串的内容,如下所示:
$newString1 = 'Castanho';
$newString2 = 'Cor de Rosa';
Run Code Online (Sandbox Code Playgroud)
我怎样才能在PHP中做到这一点.需要一些线索.
最好的祝福,
我正在寻找php sprintf函数的C#等价物.
我有下面的字符串:
"There are %s hits, %s are an exact match."
Run Code Online (Sandbox Code Playgroud)
我希望%s用查询返回的数字替换.在PHP我会发现:
$res = sprintf("There are %s hits, %s are an exact match", $number1, $number2);
Run Code Online (Sandbox Code Playgroud)
我如何在C#中执行此操作?我想过,string.replace()但这只适用于应该更换的1件.在这种情况下有多个.
我有几个程序,其输出我无法理解:
#include <stdio.h>
int main(void)
{
int i=1;
float k=2;
printf("k is %f \n",k);
printf("i is %f \n",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出位于http://codepad.org/ZoYsP6dc
k is 2.000000
i is 2.000000
Run Code Online (Sandbox Code Playgroud)
再举一个例子
#include <stdio.h>
int main(void)
{
char i='a';
int a=5;
printf("i is %d \n",i); // here %d type cast char value in int
printf("a is %f \n",a); // hete %f dont typecast float value
printf("a is %f \n",(float)a); // if we write (float) with %f then it works
return …Run Code Online (Sandbox Code Playgroud) 我在Python(v2.6.5)中遇到字符串格式转换问题.我试着设置一个像这样格式的字符串......
os.system ('/%s/tabix' % (path) '-h -f ftp://<some_url> 4:387-388 > file.out' )
Run Code Online (Sandbox Code Playgroud)
是路径='家/约翰'
但我总是得到同样的错误
"Not enough arguments for format string"
Run Code Online (Sandbox Code Playgroud)
我阅读了文档,这篇文章没有足够的格式字符串参数,但我找不到合适的答案.
有人能帮助我吗?
提前致谢,
佩希
我有这个代码来格式化一个字符串
string s = "the first number is: {0} and the last is: {1} ";
int first = 2, last = 5;
string f = String.Format(s, first, last);
Run Code Online (Sandbox Code Playgroud)
我想提取first,并last从最终的格式化字符串(f).它意味着我要脱格式f提取first和last(我的格式为基础(s)).
有一种方式是这样的:
string.Split()(艰难和坏的方式)提取它们但我认为.Net中有一个简单的解决方案,但我不知道这是什么.
任何人都可以告诉我简单的方法是什么?
如何将C#应用程序中的日期时间值转换为具有表单的字符串6-18-2012 13:12:13.0?我一直在领先零.另外,我似乎无法进入军事时代.
我创建了一个函数dump_text(std :: ostream&),它在标准输出流中转储一些文本.文本转到文件或用户控制台.现在,我希望该文本最终出现在标准字符串对象中(请参阅下一个代码示例).
void dump_text(std::ostream &p_ostream)
{
p_ostream << "text that must endup in string object";
}
class my_class
{
public:
my_class(std::string &);
operator std::ostream & ();
};
int main(int, char **)
{
std::string l;
my_class k(l);
dump_text(k);
}
Run Code Online (Sandbox Code Playgroud)
1)CRT库中是否有'my_class'的标准实现?2)有没有人知道使用std :: ostream - 方法将文本分配给字符串的问题的更好的解决方案?
在c ++中执行此操作的最佳方法是什么(简言之,使用标准库并且易于理解):
std::string s = magic_command("%4.2f", 123.456f)
Run Code Online (Sandbox Code Playgroud)
我知道为纯c建议的snprintf malloc组合
但使用c ++有没有更好,更简洁的方法呢?
我也知道建议的std :: ostringstream方法
但我想传递ac格式字符串,如"%4.2f",我找不到用ostringstream这样做的方法.
我目前正在编写一个脚本,它对Windows目录做了一些事情,我似乎无法弄清楚我做错了什么.以下是代码的相关摘录.
import os
user = os.environ['USERNAME']
os.chdir("/users/%s/dekstop") % user
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,它会给出以下错误,
WindowsError: [Error 3] The system cannot find the path specified: '/users/%s/desktop'
Run Code Online (Sandbox Code Playgroud)
有没有理由为什么字符串格式不起作用?
我有一个案例,我必须根据具体模式生成交易号码模式如下:
MA 0000000/dd/mm/YYYY/00000
其中第一个零是随机数,那么当前日期和最后一个零应该是增量的
(00001 ... 00010 ... 00100 ... 00578)
能否请您提供正确的方法来实施此案例.