문제

Specman에서는 하나를 사용하여 변수를 문자열로 변환 할 수 있습니다.

x.to_string();

또는

x.as_a(string);

둘 사이에 차이가 있습니까? 그렇지 않다면 Specman은 왜 둘 다를 제공합니까?

도움이 되었습니까?

해결책

as_a() 표현식을 문자열뿐만 아니라 특정 유형으로 변환 할 수 있습니다.

이것들은 몇 가지 예입니다 문서

list_of_int.as_a(string)
list_of_byte.as_a(string)
string.as_a(list of int)
string.as_a(list of byte)
bool = string.as_a(bool) (Only TRUE and FALSE can be converted to Boolean; all other strings return an error)
string = bool.as_a(string)
enum = string.as_a(enum)
string = enum.as_a(string) 

업데이트:

사용 as_a(string) 그리고 to_string() 항상 같은 결과를 제공하는 것은 아닙니다.

var s: string;
s = "hello";
var lint: list of int;
lint = s.as_a(list of int);
print lint;
print lint.as_a(string);
print lint.to_string();

이것은 다음과 같은 것을 인쇄합니다.

lint =
  104
  101
  108
  108
  111
lint.as_a(string) = "hello"
list.to_string() = "104 101 108 108 111"

이 때문입니다 to_string 목록의 각 요소에서 실행되면 목록이 공간과 연결됩니다. as_a 그러나 정수를 캐릭터로 변환하고 연결하여 hello 단어.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top