Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SystemVerilog: how to extract parts of a string

789 views
Skip to first unread message

phili...@gmail.com

unread,
Apr 16, 2008, 6:23:28 PM4/16/08
to
If I have a string:

string s = "top.block_name.subblock_name";

and I want to extract the block_name from the string, how would I do
it?

I know there's a substr function

s.substr()

but there's no find() function to locate the . (dot) separator.

Thanks!

Muzaffer Kal

unread,
Apr 16, 2008, 9:26:51 PM4/16/08
to

You can always write your own find function:

function int find(int offset, string s);
int i;
for (i = offset; i < s.len(); i=i+1)
if (s.getc(i) == '.')
find = i;
return;
endfunction

and use it as following:

int firstdot = find(0,s)+1;
int nextdot = find(firstdot,s);
string blockname = s.substr(firstdot, nextdot);

Standard disclaimer: this is non-tested code which means most probably
it won't even compile at first try. Making it work is left as an
exercise for the reader.

0 new messages