如何只打印字符串的某些部分? [英] How to print only certain parts of a string?
本文介绍了如何只打印字符串的某些部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串为const char [15]
我要打印这样的:
标签一:的字符[0,13)的结果
标签二:字符[13,15)的
块引用>我如何打印字符串的唯一的某些部分?
解决方案的printf(%.13s,labelOne); //是十三字符停止。
的printf(%.3s,&放大器; labelOne [13]); //打印在offset开始的13字符串的三个字符我在您的问题或我的答案注意到一个可能的栅栏柱的错误/不一致,这取决于你的观点。对第二个例子正确的答案可能是:
的printf(%.3s,&安培; labelOne [12]);
I have a string
const char[15]
and I want to print it like this:Label-one: characters [0,13)
Label-two: characters [13, 15)How can I print only certain parts of the string?
解决方案printf( "%.13s", labelOne ); // stops after thirteen characters. printf( "%.3s", &labelOne[ 13 ] ); // prints three characters of the string that starts at offset 13
I'm noticing a possible fencepost error/inconsistency in your question or my answer, depending on your point of view. The correct answer for the second example may be:
printf( "%.3s", &labelOne[ 12 ] );
这篇关于如何只打印字符串的某些部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文