删除字符后的所有内容(以及字符) [英] Removing everything after character (and also character)

查看:138
本文介绍了删除字符后的所有内容(以及字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的字符串:

I have a string like this:

std::string string1 = "xjdfhfakdjs%54k34k.-jk34";

我需要只获取xjdfhfakdjs,但是字符串是动态的,知道它是什么,长度等,所以我想删除%之后的所有内容,还有%char。

i need to get only ""xjdfhfakdjs", but the string is dynamic, not hardcoded so I dont know what is it, the length etc. so i wanted to remove everything after %, and also the % char.

我如何做到这一点? strong>

How could i do this?

推荐答案

std :: string mystr = string1.substr(0,string1.find(%,0)) ;

std::string mystr = string1.substr(0, string1.find("%", 0));

我相信会奏效。

这篇关于删除字符后的所有内容(以及字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆