我当前正在尝试在消息的最后一个字符之后插入字符串。因此,最初的消息是:
谢谢。您的订单已收到。
现在,我想在d
和.
之间插入另一个字符串。这是我尝试过的方法,但是没有用:
$received_text = substr_replace( $received_text, ', but must be payed', substr( $received_text, - 1 ), 0 );
它正在插入我的消息的开头。任何帮助都很好!
答案 0 :(得分:1)
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<pre>
<div ng-bind-html="myText"></div>
</pre>
</div>
答案 1 :(得分:1)
您可以使用TelephonyManager tm = (TelephonyManager)context.getSystemService(Service.TELEPHONY_SERVICE);
tm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
PhoneStateListener listener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
super.onCallStateChanged(state, incomingNumber);
switch(state) {
case TelephonyManager.CALL_STATE_IDLE:
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if(incomingNumber==null) {
//outgoing call
} else {
//incoming call
}
break;
case TelephonyManager.CALL_STATE_RINGING:
if(incomingNumber==null) {
//outgoing call
} else {
//incoming call
}
break;
}
}
};
将字符串拆分为所需的部分,并在它们之间添加新的部分
substr()
答案 2 :(得分:1)
开始
如果start为非负数,则替换将从字符串的第start个偏移量开始。
如果start为负,则替换将从字符串末尾的第一个字符开始。
因此,基本上,您必须提供一个数值,以便替换从该特定位置本身开始。
执行以下操作:-
<?php
$received_text ='Thank you. Your order has been received.';
echo $received_text = substr_replace( $received_text, ', but must be payed', (strlen($received_text) - 1), 0 );
答案 3 :(得分:1)
您可以使用此代码段在任何字符串之后插入字符串。
$received_text = "Thank you. Your order has been received.";
$search_string = "received"; //string AFTER which you want to insert another
$insert_string = " now"; //string to be inserted
$position = strpos(strtolower($received_text), strtolower($search_string))+strlen($search_string); //strpos is case sensitive
$received_text = substr_replace($received_text, $insert_string, $position,0);
echo $received_text;
希望它会有所帮助:)