How to remove a long alphanumeric pattern in R - gsub

I want to remove a 32 digit ID from a string. The ID is in 32 character/digit format separated by "-"
y <- c("abcd1234-ab12-cd12-1z12-abcd1234abcd6789 Print me I am ok")
What i need is the remaining part of the string "print me I am ok"
appreciate your help!

Will this help?
string stringToTrim = "abcd1234-ab12-cd12-1z12-abcd1234abcd6789 Print me I am ok";
string result = stringToTrim.Substring(IndexOf(" ") + 1);

Related

How to look for _ in a string in a column and remove _ in SAS

I am trying to do an if statement where it finds all the observations in the column "CarBrands" that have an underscore _ in the string (it's a character), and if it has the _, then I want to remove it. How do I do this? Thanks.
You can use the FIND function to check if a string contains the underscore. Then with the COMPRESS function, you can remove the underscore.
For example;
data work.ds;
input mystring $;
datalines;
mytext
my_text
;
run;
data work.ds_1;
set work.ds;
if find(mystring,'_') > 0 then mystring = compress(mystring,'_');
else mystring = mystring;
run;
See also:
https://sasexamplecode.com/find-a-substring-in-sas/
https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n0fcshr0ir3h73n1b845c4aq58hz.htm&docsetVersion=9.4&locale=en

Golang string end character

I'm a newbie in Golang, so I'm playing with some algorithms and i have a little problem.
In java for insert an end string in char array I can do like this:
String str = "Mr John Smith ";
char[] arr = str.toCharArray();
arr[12] = '\0';
But in Golang I'm trying like this:
str := []byte("Mr John Smith ")
str[12] = '\0'
But this code didn't work
That's not a valid syntax for a rune literal with a 0 value. You can use the hex escape sequence
str[12] = '\x00'
If you really need an octal value, it requires 3 digits
str[12] = '\000'
Or just assign a literal 0
str[12] = 0
You can see the valid rune literal escape sequences in the specification: https://golang.org/ref/spec#Rune_literals

Swift adding multiple stringByReplacingOccurrencesOfString on one String?

Hello i would like to create a app that changes characters into binary code and i was wondering if there is a way to add multiple stringByReplacingOccurrencesOfString on one String or if i should take another approach to this "Problem".
Here is what i have so far
func textToBinary(theString: String) -> String {
return theString.stringByReplacingOccurrencesOfString("a",
withString: "01100001")
}
textArea.text = textToBinary(lettersCombined)
// lettersCombined is the string that i want to turn into BinaryCode.
Try this:
func textToBinary(theString : String, radix : Int = 2) -> String {
var result = ""
for c in theString.unicodeScalars {
result += String(c.value, radix: radix) + " "
}
return result
}
println(textToBinary("a"))
println(textToBinary("abc", radix: 10))
println(textToBinary("€20", radix: 16))
println(textToBinary("😄"))
(The last one is a smiley face but somehow my browser can't display it).
Edit: if you want to pad your strings to 8-character long, try this:
let str = "00000000" + String(c.value, radix: radix)
result += str.substringFromIndex(advance(str.startIndex, str.characters.count - 8)) + " "
The first line adds eight 0 the left of your string. The second line takes the last 8 characters from the padded string.

How to get the index of a String after the first space in vbsript

I'm trying to grab the first characters before a space.
I know it can be done this way
str = "3 Hello World"
str = Mid(str, 1,2)
But how would i do this after a space?
Edit: Looks like you changed your question to get characters BEFORE the first space instead of AFTER. I've updated my examples.
Here's one way:
strTextBeforeFirstSpace = Split(str, " ")(0)
Assuming a space exists in your string, this would return everything up until the first space.
Another way would be:
strTextBeforeFirstSpace = Left(str, InStr(str, " ") - 1)
You can get the index of the first space with the InStr function
InStr(str, " ")
And use this as a parameter in your Mid function
Dim str, index
str = "3 Hello World"
index = InStr(str," ")
'only neccessary if there is a space
If index > 0 Then
str = Mid(str,1,index - 1)
End If

how to remove non character letter from name field using visual foxpro

I have not used Visual FoxPro for a while. Today, my ex-colleague asks me how to remove non character from name field, i.e. only a-z and A-Z are allowed. I remember I used a function called strstran to do it. I needed to define a variable contains a-z and A-Z. But I do not remember now. Does someone knows how to handle this problem. Thanks in advance.
Use the CHRTRAN() function.
FUNCTION GetAlphaCharacters
LPARAMETERS tcExpressionSearched
LOCAL lcAllowedCharacters
m.lcAllowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
RETURN CHRTRAN(m.tcExpressionSearched, CHRTRAN(m.tcExpressionSearched, m.lcAllowedCharacters, ""), "")
ENDFUNC
Another option is to use ISALPHA(). This only looks at the left most position in the string but it's not case sensitive.
***This should work, but I haven't tested it.
myresults = ""
myvar = "MyText12"
FOR(i = 1 TO LEN(myvar))
IF ISALPHA( SUBSTR(myvar, i, 1) )
myresults = myresults + SUBSTR(myvar, i, 1)
ENDIF
ENDFOR
RETURN myresults
I know I'm a bit late to the party, but here is a function I wrote to clean out all non-printable ASCII characters from a character string.
CLEAR
* Contains ASCII characters 1 (SOH) and 2 (STX)
cTest = "Garbage Data "
? cTest
cTest = RemoveNonPrintableCharacters(cTest)
? cTest
FUNCTION RemoveNonPrintableCharacters
LPARAMETERS tcExpressionSearched
cCleanExpression = tcExpressionSearched
* Cleans out the first 32 ASCII characters, which are not printable
FOR decCount = 0 TO 31
cCleanExpression = CHRTRAN(m.cCleanExpression, CHR(decCount), "")
ENDFOR
* Also cleans out the non-printable DEL character (ASCII 127)
cCleanExpression = CHRTRAN(m.cCleanExpression, CHR(127), "")
* Return the clean string
RETURN cCleanExpression
ENDFUNC

Resources