Usuário com melhor resposta
Pegar valor

Pergunta
-
Galera tenho a string abaixo:
<Raiz CNPJ> = "Raiz CNPJ"
O regular expression pega valores da expressão acima:
Regex rege = new Regex("((\\w))+"); MatchCollection variaveis = rege.Matches(operando[0].ToString());
Porem está quebrando em quatro valores:
Raiz
Cnpj
Raiz
Cnpj
Precisava pegar em dois valores que seria o correto:
Raiz CNpj
Raiz CNpj
Como posso mudar o regular expression para pegar os valores dessa forma ?
Obrigado
SirSmart
Respostas
-
Boa tarde SirSmart,
Buscando na documentação oficial, encontrei como trabalhar com string, onde os valores não são sempre os mesmos.
https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.escape%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
Escape converts a string so that the regular expression engine will interpret any metacharacters that it may contain as character literals. For example, consider a regular expression that is designed to extract comments that are delimited by straight opening and closing brackets ([ and ]) from text. In the following example, the regular expression "[(.*?)]" is interpreted as a character class. Rather than matching comments embedded in the input text, the regular expression matches each opening or closing parenthesis, period, asterisk, or question mark.
string pattern = "[(.*?)]"; string input = "The animal [what kind?] was visible [by whom?] from the window."; MatchCollection matches = Regex.Matches(input, pattern); int commentNumber = 0; Console.WriteLine("{0} produces the following matches:", pattern); foreach (Match match in matches) Console.WriteLine(" {0}: {1}", ++commentNumber, match.Value); // This example displays the following output: // [(.*?)] produces the following matches: // 1: ? // 2: ? // 3: .
Att., Roberto Alves
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.- Marcado como Resposta Filipe B CastroModerator segunda-feira, 27 de novembro de 2017 12:15
Todas as Respostas
-
Ola SirSmart
Tudo bem contigo?
Estudaremos a sua questão e em breve traremos alguma solução.
Atenciosamente,
Guilherme Macedo S
Esse conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita
Technet Community Support
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.
-
-
-
O Texto RaizCNPJ é fixo? Não entendi bem a saída esperada. Há valores diferentes?
Juliano Nunes - http://linkedin.com/in/julianonunes
Lembre-se de clicar em "Votar como útil" e "Marcar como Resposta" caso tenha respondido sua dúvida.
Remember to "Vote as Helpful" and "Mark as Answer" if your question has been answered.
-
-
Boa tarde SirSmart,
Buscando na documentação oficial, encontrei como trabalhar com string, onde os valores não são sempre os mesmos.
https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.escape%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
Escape converts a string so that the regular expression engine will interpret any metacharacters that it may contain as character literals. For example, consider a regular expression that is designed to extract comments that are delimited by straight opening and closing brackets ([ and ]) from text. In the following example, the regular expression "[(.*?)]" is interpreted as a character class. Rather than matching comments embedded in the input text, the regular expression matches each opening or closing parenthesis, period, asterisk, or question mark.
string pattern = "[(.*?)]"; string input = "The animal [what kind?] was visible [by whom?] from the window."; MatchCollection matches = Regex.Matches(input, pattern); int commentNumber = 0; Console.WriteLine("{0} produces the following matches:", pattern); foreach (Match match in matches) Console.WriteLine(" {0}: {1}", ++commentNumber, match.Value); // This example displays the following output: // [(.*?)] produces the following matches: // 1: ? // 2: ? // 3: .
Att., Roberto Alves
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.- Marcado como Resposta Filipe B CastroModerator segunda-feira, 27 de novembro de 2017 12:15
-
Bom dia,
Por falta de retorno essa thread está encerrada.
Se necessário, favor abrir uma nova thread.
Atenciosamente,Filipe B de Castro
Esse conteúdo é fornecido sem garantias de qualquer tipo, seja expressa ou implícita
MSDN Community Support
Por favor, lembre-se de Marcar como Resposta as postagens que resolveram o seu problema. Essa é uma maneira comum de reconhecer aqueles que o ajudaram e fazer com que seja mais fácil para os outros visitantes encontrarem a resolução mais tarde.