# System Verilog- How to parse string to instantiate class

**URL:** <https://verificationacademy.com/forums/t/system-verilog-how-to-parse-string-to-instantiate-class/40559>\
**Category:** SystemVerilog\
**Tags:** System-Verilog, SystemVerilog, systemverilog-Strings, systemverilog-class-event\
**Created:** [June 21, 2022, 12:16am UTC](https://verificationacademy.com/forums/t/system-verilog-how-to-parse-string-to-instantiate-class/40559 "2022-06-21T00:16:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivamdec](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/b9e5f3/32.png) [@shivamdec](https://verificationacademy.com/forums/u/shivamdec)\
**Post date:** [June 21, 2022, 12:16am UTC](https://verificationacademy.com/forums/t/system-verilog-how-to-parse-string-to-instantiate-class/40559/1 "2022-06-21T00:16:24Z")

</div>

Hi,

I am getting a class type and assigning it to a string-

string class\_name = r\_pkt.get\_type\_name(); // r\_pkt is a class. Name of the class is router\_packet.

At this point, string class\_name has “router\_packet”

Now I want to use this string to parse the class name and instantiate it.

class\_name class\_h;

basically I want this using class name that I have in string -  
router\_packet class\_h;

How do I achieve it? Is there a system verilog construct that can parse the string and use it as class instantiation?  
Please let me know.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [June 21, 2022, 6:56pm UTC](https://verificationacademy.com/forums/t/system-verilog-how-to-parse-string-to-instantiate-class/40559/2 "2022-06-21T18:56:28Z")

</div>

_In reply to [shivamdec](https://verificationacademy.com/forums/t/system-verilog-how-to-parse-string-to-instantiate-class/40559):_

Generally, there is nothing in SystemVerilog that allows you to convert a string to an identifier. As a compiled language, you cannot form identifiers dynamically at run-time.

However there are schemes to associate strings names with the creation of class objects. The UVM has a mechanism called the “factory” which requires a registration step in the class definition, and then construction with a [create\_object\_by\_name()](https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.2/html/files/base/uvm_factory-svh.html#uvm_default_factory.create_object_by_name) method.

The UVM has an even more efficient factory scheme that avoids the use of string by using a proxy class uvm\_object\_wrapper and get\_type().
