什么是substr?在systemverilog中

时间:2015-06-26 07:45:52

标签: gcc system-verilog

Int fd;
String str;

fd = $fopen(path, "r");
Status= $fgets(str, fd);
cm = str.substr(0,1);
cm1= str.substr(0,0);

我想知道什么是substr功能?上面的目的是什么?

4 个答案:

答案 0 :(得分:1)

substr 函数返回一个新字符串,该字符串是由str的位置i到j中的字符组成的子字符串。与此处发布的示例非常相似。

module test;
  string str = "Test";
  initial
    $display(str.substr(0,1));
endmodule

输出将是:

>> Te

正如您在6.16.8节中所见,IEEE SystemVerilog Standard 1800-2012

答案 1 :(得分:1)

顾名思义,

substr 函数在systemverilog中从较大的字符串中减去或减去了一部分。

示例:

stri0 = "my_lago";
stri1 = stri0.substr(1,5);
$display("This will give stri1 = %s" , stri1);

... 输出:-这将给出stri1 = y_lag

答案 2 :(得分:-1)

假设它是c ++,它是一个返回的函数:

  

具有此对象的子字符串的字符串对象。

以下是一个例子:

// string::substr
#include <iostream>
#include <string>

int main ()
{
  std::string str="We think in generalities, but we live in details.";
                                           // (quoting Alfred N. Whitehead)

  std::string str2 = str.substr (12,12);   // "generalities"

  std::size_t pos = str.find("live");      // position of "live" in str

  std::string str3 = str.substr (pos);     // get from "live" to the end

  std::cout << str2 << ' ' << str3 << '\n';

  return 0;
}

将输出:

  

普遍性存在于细节中。

在您的情况下,我们假设fget将Hello stackoverflow放入str

str.substr(0,1);// This takes from index 0 & lenght 1
                // It's "H"
str.substr(0,0);// This takes from index 0 & lenght 0
                // It's an empty string

答案 3 :(得分:-1)

子串:此方法提取字符串。它需要子串的位置(起始索引,长度)。然后它返回一个包含该范围内字符的新字符串。

C#program Substring

使用System;

class Program
{
    static void Main()
    {
    string input = "ManCatDog";

    // Get Middle three characters.
    string subString = input.Substring(3, 6);
    Console.WriteLine("SubString: {0}", subString);
    }
}

输出

子串:猫