i'm using PFM module of DOORS. I have to write to a file some information from a configuration in PFM.
I want all the paramaters with name, value and unit. The following is the code i tried, but couldn't get all the paramters
DxlObject paramdxl = null
DxlObject comp = CONF_getCompVersion(node)
DxlObject progV = CONF_getUsingProgVersion (comp)
param = CONF_getAllParams(comp, progV)
for paramdxl in param do{
string name1 = paramdxl->"name"
string unit1 = paramdxl->"unit"
string value1 = ""
string value2 = ""
string name2 = ""
for value1 in paramdxl->"values" do{
}
print "name: "name1 " value : " value1 " unit: " unit1 "\n"
}
According to the PFM API, values of parameter is contained in Skip list.
But value1 contains ''Standard layout'' instead of the value whereas the other values (name and unit) are correct.
Thank you for your help.
SOLVED :
Here is the code to export in file.csv list of criteria (with state) and parameters (with value and unit) from a configuration. This can be easily modify to export all elements in all configuration in a project PFM.
//Path of CSV file
Stream outcrit = write "C:\\YOURPATH\\crit.csv"
Stream outparam = write "C:\\YOURPATH\\param.csv"
string separator = ";"
string endline = "\n"
outcrit<< "famille"separator"nom"separator"etat"endline
outparam<< "nom"separator"valeur"separator"unite"endline
Skip param = create
Skip param2 = create
Skip crit = create
Skip critSet = create
Skip values1 = createString
string c = ""
string p = ""
string message = ""
string data = ""
DxlObject dxlParam = null
DxlObject dxl = null
DxlObject dxlCritSet = null
DxlObject dxlCrit = null
int n = 1
int type = CONF_getNodeType(node)
if (type == CONF_PROG){ //Configuration selected
infoBox "toto"
DxlObject dxlConfig = null
dxlConfig = node->"lastVersion" //Get Configuration set
Skip activOpt = dxlConfig->"activOptions" //Get Criteria activated
Skip packVer = dxlConfig->"compVersions" //Get list of package version
DxlObject dxlPackVer = null
for dxlPackVer in packVer do{ //Get Object package Version
}
DxlObject progV = CONF_getUsingProgVersion (dxlPackVer)
critSet = dxlPackVer->"variantsets" //Get list of criteria
param = dxlPackVer->"params" //Get list of parameters
print "Listes des criteres \n"
for dxlCritSet in critSet do{
string nameF = dxlCritSet->"name" //Name of criteria set
print "famille :" nameF "\n"
crit = dxlCritSet->"options"
for dxlCrit in crit do{
string nameCrit = dxlCrit->"name" //Name of criteria
bool stateCrit = false
if (find(activOpt, dxlCrit)){
stateCrit = true //Update state of criteria
}
print "name :" nameCrit " state : "stateCrit"\n"
outcrit<< nameF separator nameCrit separator stateCrit endline
}
}
print "Listes des parametres \n"
for dxlParam in param do{
string nameParam = dxlParam->"name" //Parameter name
string unitParam = dxlParam->"unit" //Parameter unit
param2 = dxlParam->"values"
string valueParam = ""
find (param2, progV, valueParam) //get parameter value
print "Parametre " nameParam " : " valueParam " " unitParam "\n"
outparam<< nameParam separator valueParam separator unitParam endline
}
close outcrit
close outparam
nicodupe
Related
I have a subroutine that I pass a string value from a skip list. That value is compared to objects in a Doors File. But the comparison does not work.
Skip split (string s, string delim)
{
Skip skp = create
int i = 0
Regexp split = regexp "^(.*?)" delim "(.*)$"
while (split s)
{
string temp_s = s[match 2]
put(skp, i++, s[match 1] "")
s = temp_s
}
put(skp, i++, s "")
return skp
}
string getInfo( string inStr)
{
for currObj in currMod do
{
if ( findPlainText( ( currOBJ.SW_VRC ""), inStr, offsetFromFind, lengthFromFind, false ) )
{
print currOBJ.SW_VRC " matches " inStr "\n";
}
}
}
Skip newLst = split(modname, ",") // this just splits a string input into parameters separated by commas
string inputInfo;
find(newLst, 0, inputInfo)
getInfo(inputInfo)
Now this is a simplified version of what I am doing. But the findPlainText does not match anything. inputInfo is getting the correct string, I checked.
The part that really kills me is if I hardcode in the parameter
i.e. inStr = "21";
It works like it's supposed to.
Now I was assuming a string is a string. Is there a difference between a string from a skip list and a string that's quoted? Is there a hidden character?
What am I missing? Any insight you could provide would be welcome.
Thanks,
DevM
your snippet works, but I had to add some variables to make it work, and I don't have a split function at hand:
Skip split (string s, string delim)
{
Skip skp = create
int i = 0
Regexp split = regexp "^(.*?)" delim "(.*)$"
while (split s)
{
string temp_s = s[match 2]
put(skp, i++, s[match 1] "")
s = temp_s
}
put(skp, i++, s "")
return skp
}
string SW_VRC="Object Text"
Module currMod = current Module
string getInfo( string inStr)
{
int offsetFromFind, lengthFromFind
string resultString = ""
Object currObj
for currObj in currMod do
{
if ( findPlainText( ( currObj.SW_VRC ""), inStr, offsetFromFind, lengthFromFind, false ) )
{
print currObj.SW_VRC " matches " inStr "\n";
resultString = resultString "\n" currObj.SW_VRC ""
}
}
return resultString
}
string modname = "a,b,cc,ccc,d,e,f"
Skip newLst = split (modname,",")
string inputInfo= "";
find(newLst, 0, inputInfo)
getInfo(inputInfo)
Perhaps you removed too much information when preparing this post?
Or you don't have an entry with the key "0" in newLst? What happens if you start your function with
string inputInfo
inputInfo = "21"
getInfo (inputInfo)
?
Is there a way to split a string by some symbol but only at first occurrence?
Example: date: '2019:04:01' should be split into date and '2019:04:01'
It could also look like this date:'2019:04:01' or this date : '2019:04:01' and should still be split into date and '2019:04:01'
string.split(':');
I tried using the split() method. But it doesn't have a limit attribute or something like that.
You were never going to be able to do all of that, including trimming whitespace, with the split command. You will have to do it yourself. Here's one way:
String s = "date : '2019:04:01'";
int idx = s.indexOf(":");
List parts = [s.substring(0,idx).trim(), s.substring(idx+1).trim()];
You can split the string, skip the first item of the list created and re-join them to a string.
In your case it would be something like:
var str = "date: '2019:04:01'";
var parts = str.split(':');
var prefix = parts[0].trim(); // prefix: "date"
var date = parts.sublist(1).join(':').trim(); // date: "'2019:04:01'"
The trim methods remove any unneccessary whitespaces around the first colon.
Just use the split method on the string. It accepts a delimiter/separator/pattern to split the text by. It returns a list of values separated by the provided delimiter/separator/pattern.
Usage:
const str = 'date: 2019:04:01';
final values = string.split(': '); // Notice the whitespace after colon
Output:
Inspired by python, I've wrote this utility function to support string split with an optionally maximum number of splits. Usage:
split("a=b=c", "="); // ["a", "b", "c"]
split("a=b=c", "=", max: 1); // ["a", "b=c"]
split("",""); // [""] (edge case where separator is empty)
split("a=", "="); // ["a", ""]
split("=", "="); // ["", ""]
split("date: '2019:04:01'", ":", max: 1) // ["date", " '2019:04:01'"] (as asked in question)
Define this function in your code:
List<String> split(String string, String separator, {int max = 0}) {
var result = List<String>();
if (separator.isEmpty) {
result.add(string);
return result;
}
while (true) {
var index = string.indexOf(separator, 0);
if (index == -1 || (max > 0 && result.length >= max)) {
result.add(string);
break;
}
result.add(string.substring(0, index));
string = string.substring(index + separator.length);
}
return result;
}
Online demo: https://dartpad.dev/e9a5a8a5ff803092c76a26d6721bfaf4
I found that very simple by removing the first item and "join" the rest of the List
String date = "date:'2019:04:01'";
List<String> dateParts = date.split(":");
List<String> wantedParts = [dateParts.removeAt(0),dateParts.join(":")];
Use RegExp
string.split(RegExp(r":\s*(?=')"));
Note the use of a raw string (a string prefixed with r)
\s* matches zero or more whitespace character
(?=') matches ' without including itself
You can use extensions and use this one for separating text for the RichText/TextSpan use cases:
extension StringExtension on String {
List<String> controlledSplit(
String separator, {
int max = 1,
bool includeSeparator = false,
}) {
String string = this;
List<String> result = [];
if (separator.isEmpty) {
result.add(string);
return result;
}
while (true) {
var index = string.indexOf(separator, 0);
print(index);
if (index == -1 || (max > 0 && result.length >= max)) {
result.add(string);
break;
}
result.add(string.substring(0, index));
if (includeSeparator) {
result.add(separator);
}
string = string.substring(index + separator.length);
}
return result;
}
}
Then you can just reference this as a method for any string through that extension:
void main() {
String mainString = 'Here was john and john was here';
print(mainString.controlledSplit('john', max:1, includeSeparator:true));
}
Just convert list to string and search
productModel.tagsList.toString().contains(filterText.toLowerCase())
how can i use delimiter " : " to receive a string from (system.in ) E.g Ben : 50. Jessica : 30 and so on , and then print as Ben, 50 using my own System.out.print (name + "," + score); I was able to print out the string as string but its not printing out the integer as integer. I need to calculate the average of all the score and that is why i need integer to remain integer so the average method can work Here is my code . Here is my code so far. Please help !!!
-------------------------------------------------------------------------
import java.util.Scanner;
public class StudentScore{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
input.useDelimiter(":");
System.out.print("Please enter your name and score in format: Ben : 50" );
String name = input.next();
int score = input.nextInt();
while(input.hasNext() || input.hasNextInt());{
System.out.println(name + ", " + score);
}
input.close();
}
}
this keeps creeating a new scanner and no print out.
After researching and asking several people , i found out the String class actually has a function that takes in string and then splits it into several primitive values" long", " int" and so on. You need to convert your input into an array, make sure it is spitted by a delimiter of choice .e.g "," or ":" in my own case. Then the array will be your parameter for the .split method from the String class. I posted my complete program below. The programs takes in three names and score and outputs the grade letter and then tells the best score among the three students.
import java.util.Scanner;
public class ThreeNamesAndScore {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please enter your name and score in this format, Name : Score");
String input1 = input.nextLine();
String[] userData1 = input1.split(":");
String firstStudentName = userData1[0];
String firstStudentStrScore = userData1[1];
int firstStudentScore = Integer.parseInt(firstStudentStrScore);
System.out.print("Please enter your name and score in this format, Name : Score");
String input2 = input.nextLine();
String[] userData2 = input2.split(":");
String secondStudentName = userData2[0];
String secondStudentStrScore = userData2[1];
int secondStudentScore = Integer.parseInt(secondStudentStrScore);
System.out.print("Please enter your name and score in this format, Name : Score");
String input3 = input.nextLine();
String[] userData3 = input3.split(":");
String thirdStudentName = userData3[0];
String thirdStudentStrScore = userData3[1];
int thirdStudentScore = Integer.parseInt(thirdStudentStrScore);
System.out.println("The following is the fianl result ");
System.out.println(firstStudentName + ", " + getGradeLetter(firstStudentScore));
System.out.println(secondStudentName + ", " + getGradeLetter(secondStudentScore));
System.out.println(thirdStudentName + ", " + getGradeLetter(thirdStudentScore));
System.out.println("The best score is from " + bestScore(input1, input2, input3));
input.close();
}
public static String getGradeLetter(int score) {
if (score >= 90) {
return "A";
} else if (score >= 80) {
return "B";
} else if (score >= 70) {
return "C";
} else if (score >= 60) {
return "D";
} else
return "F";
}
public static String bestScore(String a, String b, String c) {
String bestStudent;
String[] userInputs = { a, b, c };
String[] user1 = a.split(":");
String aStrScore = user1[1];
int aScore = Integer.parseInt(aStrScore);
String[] user2 = b.split(":");
String bStrScore = user2[1];
int bScore = Integer.parseInt(bStrScore);
String[] user3 = c.split(":");
String cStrScore = user3[1];
int cScore = Integer.parseInt(cStrScore);
if ((aScore > bScore) && (aScore > cScore))
bestStudent = a;
else if ((bScore > aScore) && (bScore > cScore))
bestStudent = b;
else
bestStudent = c;
return bestStudent;
}
}
I'm making a simple String Tokenizer in Swift like I would in Java...but it's really not working out for me.
The end of each line in my data source delimited with "^" and the data is separated by comma's.
For example: "string 1,string 2,string 3,^,string 1,string 2,string 3,^"
This is what I would do in Java...(I only want the first two strings in each line of data)
String delimeter = "^";
StringTokenizer tokenizedString = new StringTokenizer(responseString,delimeter);
String [] stringArray = new String [tokenizedString.countTokens()];
StringTokenizer tokenizedAgain;
String str1;
String str2;
String token;
for(int i =0; i< stringArray.length; i ++)
{
token = tokenizedString.nextToken();
tokenizedAgain = new StringTokenizer(token, ",");
tokenizedAgain.nextToken();
str1 = tokenizedAgain.nextToken();
str2 = tokenizedAgain.nextToken();
}
If someone could point me in the right direction that would really helpful.
I've looked at this: Swift: Split a String into an array
and this: http://www.swift-studies.com/blog/2014/6/23/a-swift-tokenizer
but I can't really find other resources on String Tokenizing in Swift. Thanks!
This extends Syed's componentsSeperatedByString answer but with Swift's map to create the requested Nx2 matrix.
let tokenizedString = "string 1, string 2, string 3, ^, string a, string b, string c, ^"
let lines = tokenizedString.componentsSeparatedByString("^, ")
let tokens = lines.map {
(var line) -> [String] in
let token = line.componentsSeparatedByString(", ")
return [token[0], token[1]]
}
println(tokens)
var delimiter = "^"
var tokenDelimiter = ","
var newstr = "string 1, string 2, string 3, ^, string 1, string 2, string 3,^"
var line = newstr.componentsSeparatedByString(delimiter) // splits into lines
let nl = line.count
var tokens = [[String]]() // declares a 2d string array
for i in 0 ..< nl {
let x = line[i].componentsSeparatedByString(tokenDelimiter) // splits into tokens
tokens.append(x)
}
println(tokens[0][0])
I'm using for for a year but now I have to modify small scripts and I'm a newbie with DXL. I have searched in before questions but I don't know how I can do it.
I have to develope a script that analyzes all objects in the same formal module to extract from each "object text" different strings separated by tab, to be written in other different attributes of the same object.
The formal module contents has been imported from Word. In that way that normal text format is defined as "object text" and every Title style is associated to a given level heading. In that way each object is provided with object heading or object text (but not both at the same time). Objects with object heading doesn't require any further action. However for objects provided with object text, I have to extract from object text some atributes separated by tabs.
For example a typical object text could be:
NNNN TEXT/TABLE/OLE OBJECT/ANY OTHER STRING (XXXXXX) (YYYYYY)
After apply the script it should be converted as:
Attribute 1: NNNN
Object Text: TEXT/TABLE/OLE OBJECT/ANY OTHER STRING
Attribute 2: XXXXXX
Attribute 3: YYYYYY
I have small script as example but I have passed all the morning trying to modify it to get I need but I can't do it:
Object o = current
//bool get_text(Object o) {return o."Object Heading" "" != ""}
string get_text(Object o)
{
if (o."Object Heading" "" != "")
return "Object Heading"
else
return "Object Text"
}
Regexp r_id = regexp "(http://0-9a-z/.+) "
for o in current Module do
{
string texto = o.(get_text(o))
if (r_id text)
{
o."Attribute 1" = textmatch 1
string input = richTextWithOle(o.(get_text(o)))
string output = cutRichText(input, 0, length(textmatch 1))
o.(get_text(o)) = richText(output)
}
}
This was a complicated one, but I think I have it figured out. Thanks for posting this because I may find it useful in the future as well.
I tried this out and it seems to work:
Object o
string get_text(Object o)
{
if (o."Object Heading" "" != "")
return "Object Heading"
else
return "Object Text"
}
char cTab = '\t' //The tab character to find
Buffer b = create
string tmp = "" //Needed to concatenate buffer parts
int offset = 0
for o in current Module do
{
string attr = get_text(o)
b = o.attr //Put the contents in the buffer
offset = contains(b, cTab) //Find the first tab
o."Attribute 1" = b[0:offset-1] //Set the first Attribute
b = b[offset+1:] //Remove the first attribute from the text
offset = contains(b, cTab)
if(offset > -1)
{
if(attr == "Object Heading") o.attr = b[0:offset-1]
b = b[offset+1:]
offset = contains(b, cTab)
if(offset > -1)
{
o."Attribute 2" = b[1:offset-2] //Set the second Attribute without the ()
b = b[offset+1:]
o."Attribute 3" = b[1:length(b)-2] //Set the third Attribute without the ()
} else {
o."Attribute 2" = b[1:length(b)-2] //Set the second Attribute without the ()
}
} else {
if(attr == "Object Heading") o.attr = b[0:]
}
if(attr == "Object Text")
{
b = richTextWithOle(o.attr) "" //This section removes the attributes from the contents without losing the rich text formatting and OLEs that may be present.
string word = o."Attribute 1"
offset = contains(b, word, 0)
tmp = b[0:offset-1] "" b[(offset+length(word)+5):]
b = tmp
word = "(" o."Attribute 2" ")"
offset = contains(b, word, 0)
if(offset > -1)
{
tmp = b[0:offset-6] "" b[offset+length(word):]
b = tmp
}
word = "(" o."Attribute 3" ")"
offset = contains(b, word, 0)
if(offset > -1)
{
tmp = b[0:offset-6] "" b[offset+length(word):]
}
o.attr = richText(tmp) //Set the Object Text or Heading
}
}
delete b //Release the buffer resources
Let me know if this gives you any trouble or if you want more detailed explination of the code.
EDIT: I updated the above code to take care of the issues you mentioned. It should be all set now. Let me know if you have any more trouble with it.