Vugen scripting Code: Does anyone have the code for spliting astring into two substrings?
Question ID: 104774
1
0

I have an 18 character string that I need to split into two. The first 8 characters will go in one string, the remaining 10 into another string. I can pull out the first 8 characters no problem with the strcpy function. It's the remaining 10 that is giving me problems. From everything I've goggled it looks like the only way to do this is with a custom function that loops through the original character string and builds the new one character by character. Am I missing something?

I'm hoping one of you can help me out.

Marked as spam
Posted by (Questions: 231, Answers: 18)
Asked on December 22, 2012 5:27 pm
56 views
Answers (1)
1
Private answer

The solution:

charsOriginalString[19]=''123456789012345678'';// 18-char string
chars1stString[9];// 8 characters plus end char
chars2ndString[11];// 10 characters plus end char

intbeginIndex,endIndex;
intiLen1stString=8;// Assume this length is a given

lr_output_message(''The value of sOriginalString=%s'',lr_eval_string(sOriginalString));

strncpy(s1stString,sOriginalString,iLen1stString);// copy the 1st string using the original 18-char string's first 8 characters
lr_output_message(''The value of s1stString=%s'',lr_eval_string(s1stString));

beginIndex=strlen(s1stString);// assign the beginning index value to bethe length of 1st string
lr_output_message(''The value of beginIndex is=%d'',beginIndex);

endIndex=strlen(sOriginalString);// assign the ending index value to be the length of the original string
lr_output_message(''The value of endIndex is=%d'',endIndex);

strncpy(s2ndString,sOriginalString+beginIndex,endIndex-beginIndex);
lr_output_message(''The value of s2ndString=%s'',lr_eval_string(s2ndString));

Marked as spam
Posted by (Questions: 12, Answers: 384)
Answered on December 22, 2012 5:33 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top