A foreigner pleads guilty to raping a local woman on a capital street at night. A judge remarks in court that the man’s crime is “uncharacteristic” of the minority ethnic community to which he belongs. A police officer agrees, saying: “Well I have never come across it before.”

That was in Ireland this week.

In another country, an online video (warning: it’s disturbing) shows a foreigner being beaten after, apparently, molesting a woman on a street in the capital. Commenters online call for the foreigner to be “beaten to death.” Days later, the police launch a 100-day “clean out foreigners” campaign, with a hotline for citizens to report suspected violations of immigration, residency or work rules. A well-known TV host, supporting the campaign, calls for “foreign trash” to be thrown out of the country and is quoted as calling a recently-expelled journalist a “foreign bitch.”

That was in China last week.

To be sure, racism exists in Ireland, and plenty of Chinese are very friendly toward foreigners. The Beijing police said the 100-day campaign and the alleged molestation incident were not linked, though many Chinese netizens made the connection.

Still, the difference between the responses to the two incidents is striking.

On his Sina Weibo site, a microblogger who says he is a Canadian living in Beijing commented pointedly: “Strangely, Ireland didn’t freak out and start talking about kicking out foreigners.”

“Come on China. Being sensible is not so difficult…even the Irish can do it! Hehehehe” joked another microblogger, who described himself as a “Kiwi in Beijing for 15+ years.”

Being a foreigner in China today is an uneasy business.

As a Hong Kong-born, non-ethnic-Chinese resident, in the more than three decades I’ve lived in China I have never experienced so much disquiet; never looked over my shoulder quite as much, wondering if the person I just passed on the street will whip out his cellphone and report me to the foreigner hotline; never worried whether the people on a bus will turn on me for arguing with a bus conductor who is ignoring my questions about the route.

So far, the Chinese police have remained silent on the fate of the man, believed to be a British tourist, in the video that sparked the outcry earlier this month. His exact whereabouts, whether he has been charged in connection with the apparent molestation, even his name — all remain unclear, though he is thought to be in custody. The police campaign against so-called “Three No” foreigners (that is, those violating immigration, residency or work rules) continues.

In Ireland, as we know from media reports, the convicted rapist was Hong Zhi Yang, 23. On Monday, he was sentenced to eight years in jail, three suspended. As he pleaded guilty last week, he apologized to his victim, the police and the Irish justice system.

“I am sick to the stomach. I have never hurt a human being before,” he said, adding that he knew he had brought dishonor to his family and great shame to his name. His lawyer said he was drunk at the time of the attack.

In China, the TV host Yang Rui has stoutly defended his online reference to “foreign trash,” recently saying he was considering legal action against a blogger who accused him of being xenophobic. Charlie Custer, editor of China Geeks, has damaged his reputation, Mr. Yang said.

Mr. Yang, the host of “Dialogue,” an English-language show on CCTV News, says his “foreign bitch” remark was mistranslated, and that the English word should have been “shrew” or “harridan.” (For a full report on the controversy over the anchor’s comments, see this by Brendan O’Kane.)

Mr. Yang wrote to The Wall Street Journal that “Singling out these Foreign Trash serves to protect the good reputation of decent Westerners.”

Still, another post from Mr. Yang touches on a question that has been occurring to others: Is this new atmosphere going to be a part of China’s rise?

Commenting on the “foreign trash” controversy, Mr. Yang wrote: “West-centric era should be over. The rise of the rest is changing the world. Period.”

In another case of a foreigner’s behavior provoking outrage, a Russian cellist who insulted a Chinese woman on a train after she complained that his feet were on her seat was fired Tuesday by his employer, the Beijing Symphony Orchestra, the China Daily reports. The cellist, Oleg Vedernikov, had earlier apologized for his behavior.