简体   繁体   English

在八度中删除字符串的一部分

[英]Remove part of a string in Octave

What is the most efficient way to remove part of a string and save it in one variable and the rest in other variable? 删除字符串的一部分并将其保存在一个变量中,将其余部分保存在另一个变量中,最有效的方法是什么?

I tried something with substring but it's just to long. 我尝试了一些用子串的方法,但是时间太长了。 Does a function for this exist that i'm missing 我是否缺少为此功能存在

You don't need a function for that. 您不需要为此的功能。 You just use indexing: 您只需要使用索引:

a = "long string";
b = a(1:4);    # b is "long"
c = a(5:end);  # c is " string"

your problem then becomes finding the point where to split your string but that is dependent on your specific case. 然后,您的问题就变成了找到分割字符串的点,但这取决于您的具体情况。 Possible functions for that are strfind , strmatch , regexp , and index . 可能的功能为strfindstrmatchregexpindex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM